static void Main()
        {
            Shape[] list = new Shape[]
            {
                new Triangle(2,4),
                new Square(5),
                new Triangle(3,4),
                new Rectangle(2,5)
            };

            TestCalculateSurface test = new TestCalculateSurface(list);
            Console.WriteLine("Test result: {0}", test.TestPassed ? "SUCCESS!": "TEST FAILED");
        }
Example #2
1
        static void Main()
        {
            Shape[] shapes = new Shape[] {
                                            new Triangle(4,5),
                                            new Rectangle(4,5),
                                            new Square(4),
                                         };

            foreach (var shape in shapes)
            {
                Console.WriteLine(shape.CalculateSurface());
            }
        }
 static void Main()
 {
     Shape[] shapes = new Shape[] { new Triangle(4.5m, 2.1m),
                                    new Rectangle(6.5m, 2.4m),
                                    new Square(7) };
     foreach (var shape in shapes)
     {
         string nameOfShape = shape.GetType().Name;
         Console.WriteLine("The surface of a {0} with sides {1} and {2} is: {3:F2}", nameOfShape, shape.Height, shape.Width, shape.CalculateSurface());
     }
 }
Example #4
0
        //method for printing shape 
        public static void PrintShape(Shape shape)
        {
            if (shape is Square)
            {
                Console.WriteLine("Square with side {0}.", shape.Width);
            }

            else
            {
                Console.WriteLine("{0} with width {1} and height {2}.", shape.GetType().Name, shape.Width, shape.Height);
            }

        }
Example #5
0
 static void Main()
 {
     Shape[] shapes = new Shape[]
     {
         new Triangle(3,4),
         new Rectangle(3,4),
         new Circle(3)
     };
     foreach (Shape item in shapes)
     {
         Console.WriteLine(item);
     }
 }
        static void Main()
        {
            var shapes = new Shape[3];

            shapes[0] = new Rectangle(3, 4);
            shapes[1] = new Triangle(3, 4);
            shapes[2] = new Square(3);

            foreach (var shape in shapes)
            {
                Console.WriteLine(shape.CalculateSurface());
            }
        }
Example #7
0
 /* Define abstract class Shape with only one abstract method CalculateSurface()
    and fields width and height.
    Define two new classes Triangle and Rectangle that implement the virtual method
    and return the surface of the figure
    (height * width for rectangle and height * width/2 for triangle).
    Define class Square and suitable constructor so that at initialization height
    must be kept equal to width and implement the CalculateSurface() method.
    Write a program that tests the behaviour of the CalculateSurface() method
    for different shapes (Square, Rectangle, Triangle) stored in an array.
  */
 public static void Main()
 {
     Shape[] shapes = new Shape[]
     {
         new Rectangle(5.0, 4.5),
         new Triangle(3.1, 5.5),
         new Square(3.5)
     };
     foreach (var shape in shapes)
     {
         Console.WriteLine("{0:F2}", shape.CalculateSurface());
     }
 }
 static void Main(string[] args)
 {
     Shape[] shapes = new Shape[]
                             {
                                 new Rectangle(5.5m, 4.5m),
                                 new Triangle(3.14m, 3.54m),
                                 new Square(3.56m)
                             };
     foreach (var shape in shapes)
     {
         Console.WriteLine("{0:F2}", shape.CalculateSurface());
     }
 }
Example #9
0
        public static void Main()
        {
            Shape[] shapes = new Shape[]{
                new Circle(5),
                new Triangle(5, 10),
                new Rectangle(5, 10),
                new Square(7)
            };

            foreach (var shape in shapes)
            {
                Console.WriteLine("Shape: {0} Surface: {1}", shape.GetType().Name, shape.CalculateSurface());
            }
        }
Example #10
0
        static void Main()
        {
            Shape[] shapes = new Shape[]
            {
                new Rectangle(5.5,3),
                new Circle(3.3),
                new Triangle(5.1,2.3)
            };

            foreach (var shape in shapes)
            {
                Console.WriteLine("{0}, bounding box width: {1}, bounding box height: {2}, shape area is {3}", shape.GetType(), shape.Width, shape.Height, shape.CalculateSurface());
            }
        }
Example #11
0
        static void Main()
        {
            Shape[] shapesArray = new Shape[]
                    {
                        new Rectangle() {Height = 1, Width = 2},
                        new Square(2.45),
                        new Triangle() {Width = 5.5, Height = 6.5}
                    };

            foreach (Shape shape in shapesArray)
            {
                Console.WriteLine(shape.CalculateSurface());
            }
        }
Example #12
0
        static void Main()
        {
            Shape[] testShapes = new Shape[]
            {
                new Triangle(2.0, 2.2),
                new Rectangle(2.0, 2.0),
                new Circle(2.0)
            };

            for (int i = 0; i < testShapes.Length; i++)
            {
                Console.WriteLine(testShapes[i].CalculateSurface());
            }
        }
Example #13
0
        static void Main()
        {
            var shapes = new Shape[]
            {
                new Triangle(5, 4),
                new Rectangle(5, 6),
                new Square(6),
                new Circle(20)
            };

            foreach (var item in shapes)
            {
                Console.WriteLine("Surface of {0} with width {1}, height {2} = {3}", item.GetType().Name.ToLower(), item.Width, item.Height, item.CalculateSurface());
            }
        }
 private bool IsValidSurfaceCalculator( Shape[] shapes)
 {
     for (int i = 0; i < shapes.Length; i++ )
     {
         try
         {
             Console.WriteLine("{0} {1} with surface:{2}", shapes[i].GetType(), i , shapes[i].CalculateSurface());
         }
         catch
         {
             return false;
         }
     }
     return true;
 }
Example #15
0
        static void Main()
        {
            var shapesCollection = new Shape[]{
                new Triangle(10.5,12),
                new Triangle(5.5,6),
                new Square(10.5),
                new Square(9),
                new Rectangular(10.5,12),
                new Rectangular(10.5,12)
            };

            foreach (var shape in shapesCollection)
            {
                Console.WriteLine("size of shape is: {0}",shape.CalculateSurface());
            }
        }
        static void Main()
        {
            Shape[] shapes = new Shape[]
                                {
                                    new Rectangle(4, 2),
                                    new Triangle(4, 2),
                                    new Square(2),
                                    new Rectangle(1.5, 2.5)
                                };

            foreach (var item in shapes)
            {
                Console.WriteLine(item);
                Console.WriteLine("Surface: {0}", item.CalculateSurface());
            }
        }
        static void Main()
        {
            Shape[] shapes = new Shape[]
            {
                new Rectangle(5,6),
                new Triangle(6,7),
                new Square(5)
            };

            Console.WriteLine("Surfaces of the shapes:");

            foreach (var shape in shapes)
            {
                Console.WriteLine(shape);
                Console.WriteLine(shape.CalculateSurface());
            }
        }
        public static void Main()
        {
            var triangle = new Triangle(10.5, 8.5);
            var rectangle = new Rectangle(8d, 8d);
            var circle = new Circle(5d);

            var shapes = new Shape[] 
            {
                triangle, rectangle, circle
            };

            foreach (Shape shape in shapes)
            {
                var result = new StringBuilder();
                result.AppendLine(string.Format("{0}'s surface: {1}", shape.GetType().Name, shape.CalculateSurface()));
                Console.WriteLine(result.ToString());
            }
        }
Example #19
0
        public static void Main()
        {
            while (true)
            {
                var random = new Random();

                // Fill the array with different shapes by random generator
                var shapes = new Shape[]{
                    new Rectangle(random.NextDouble() * 10, random.NextDouble() * 10),
                    new Triangle(random.NextDouble() * 10, random.NextDouble() * 10),
                    new Ellipse(random.NextDouble() * 10, random.NextDouble() * 10),
                    new Square(random.NextDouble() * 10),
                    new Circle(random.NextDouble() * 10)
                };

                // Prints the result
                foreach (var shape in shapes)
                {
                    // Prints the input data for every shape
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("{0}", shape.GetType().Name);
                    Console.ResetColor();
                    Console.WriteLine(shape);

                    // Prints the calculated surface
                    Console.Write("  surface: ");
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("{0:F}\n", shape.CalculateSurface());
                    Console.ResetColor();
                }

                // Prints the menu
                Console.Write("\nPress "); Console.ForegroundColor = ConsoleColor.Green;
                Console.Write("<"); Console.ResetColor();
                Console.Write("Esc"); Console.ForegroundColor = ConsoleColor.Green;
                Console.Write(">"); Console.ResetColor();
                Console.Write(" to exit or any other key to continue the test . . .");

                // Reads some input key
                if (Console.ReadKey().Key != ConsoleKey.Escape) Console.Clear();
                else break;
            }
        }
        static void Main()
        {
            var shapes = new Shape[]
                {
                    new Triangle(4,5),
                    new Triangle(56.7,33.45),
                    new Triangle(14,7),
                    new Rectangle(10,6),
                    new Rectangle(12.36,8.9),
                    new Rectangle (3,3),
                    new Square (5),
                    new Square(7.3),
                    new Square(36.9)
                };

            foreach (var shape in shapes)
            {
                Console.WriteLine("{0}, Surface: {1}", shape.GetType(), shape.CalculateSurface());
            }
        }
        static void Main(string[] args)
        {
            Shape[] shapeArray = new Shape[]
            {
                new Square(4.555),
                new Rectangle(4.555, 3),
                new Square(3),
                new Rectangle(55.5, 3),
                new Triangle(455.5, 78.3),
                new Square(55),
                new Triangle(5.55, 3),
                new Triangle(5, 33.3),
                new Triangle(4.555, 3.3)
            };

            for (int i = 0; i < shapeArray.Length; i++)
            {
                Console.WriteLine(shapeArray[i].CalculateSurface());
            }
        }
        static void Main()
        {
            Triangle triangle = new Triangle(2, 3);
            Rectangle rectangle = new Rectangle(2, 3);
            Square square = new Square(2);
            Console.WriteLine("Triangle area is {0}", triangle.CalculateSurface());
            Console.WriteLine("Rectangle area is {0}", rectangle.CalculateSurface());
            Console.WriteLine("Square area is {0}", square.CalculateSurface());

            //Write a program that tests the behaviour of the CalculateSurface() method
            //for different shapes (Square, Rectangle, Triangle) stored in an array

            Shape[] all = new Shape[]
            {   new Triangle (2,3),
                new Rectangle(2,3),
                new Square (3)
            };

            foreach (Shape shape in all)
            {
                Console.WriteLine("{0} is the area of the object {1}",
                    shape.CalculateSurface(), shape.GetType());
            }
        }
 public void PrintShapeArea(Shape shape)
 {
     Console.WriteLine("Area is: {0}", shape.GetArea());
 }
 static void ShowShape(Shapes.Shape shape)
 {
     WriteLine($"Area = {shape.Area}\t\tPerimeter = {shape.Perimeter}\t\tUom = {shape.UoM}");
 }
 public TestCalculateSurface(Shape[] shapes)
 {
     this.Shapes = shapes;
     this.TestPassed = IsValidSurfaceCalculator(shapes);
 }