-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
83 lines (68 loc) · 2.74 KB
/
Copy pathProgram.cs
File metadata and controls
83 lines (68 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ShapeApplication
{
public class Program
{
static void Main(string[] args)
{
// Create a Circle object
Circle circle = new Circle(1);
Console.WriteLine(circle.ToString());
// Create a Triangle object
Triangle triangleFirst = new Triangle(5, 8, 9);
Console.WriteLine(triangleFirst.ToString());
Triangle triangleSecond = new Triangle(3, 3, 3);
Console.WriteLine(triangleSecond.ToString());
Triangle triangleThird = new Triangle(4, 4, 5);
Console.WriteLine(triangleThird.ToString());
// Create a Rectangle object
Rectangle rectangle = new Rectangle(3, 3);
Console.WriteLine(rectangle.ToString());
// Create a Square object
Square square = new Square(3);
Console.WriteLine(square.ToString());
// Create a List of Shape type object
List<Shape> baseShapes = new List<Shape>();
baseShapes.Add(circle);
baseShapes.Add(triangleFirst);
baseShapes.Add(triangleThird);
baseShapes.Add(rectangle);
baseShapes.Add(square);
Console.WriteLine();
var sortedList = baseShapes.OrderBy(p => p.SurfaceArea());
PrintShapes(sortedList, "Shapes ordered by Surface Area");
sortedList = baseShapes.OrderBy(p => p.Perimeter());
PrintShapes(sortedList, "Shapes ordered by Perimeter");
string Json = GetJsonString(triangleFirst);
Console.WriteLine("Json is" + Json);
PrintCountOfShapes();
Console.ReadLine();
}
private static void PrintShapes(IEnumerable<Shape> sortedList, string message)
{
Console.WriteLine(message);
foreach (var baseShape in sortedList)
{
Console.WriteLine(baseShape);
}
Console.WriteLine();
}
public static string GetJsonString(Shape obj)
{
return JsonConvert.SerializeObject(obj);
}
public static void PrintCountOfShapes()
{
Console.WriteLine();
Console.WriteLine("the number of Circle is " + Circle.Count);
Console.WriteLine("the number of triangle is " + Triangle.Count);
Console.WriteLine("the number of Square is " + Square.Count);
Console.WriteLine("the number of Rectangle is " + Rectangle.Count);
}
}
}