static void Main()
        {
            var circle = new Circle(4.0f);
            Console.WriteLine("Area of a circle with a 4.0 radius is {0}", circle.GetArea());

            var rectangle = new Rectangle(7.0, 2.0);
            Console.WriteLine("Area of a rectangle with 7.0 Height and 2.0 Width is {0}", rectangle.GetArea());

            var equilateralTriangle = new EquilateralTriangle(4.5);
            Console.WriteLine("Area of an equilateral triangle with a 4.5 long side is {0}", equilateralTriangle.GetArea());

            var square = new Square(5.0);
            Console.WriteLine("Area of a square with 5.0 long sides is {0}", square.GetArea());

            Console.ReadKey();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Circle cir1 = new Circle();

            cir1.radius = 2.5;
            cir1.Print();

            Rectangle rect1 = new Rectangle();

            rect1.height = 1.2;
            rect1.width  = 8.2;
            rect1.Print();

            Square sqr = new Square();

            //we've defined a variable named sqr - it's type is the class Square. sqr is one instance of the square
            sqr.LengthOfSides = 1.5;
            //this is setting the value of LengthOfSides
            double sidelength = sqr.LengthOfSides;
            double area       = sqr.GetArea();
            //execute the GetArea method of the variable sqr
            double perimeter = sqr.GetPerimeter();

            //execute the method GetPerimeter on the variable sqr
            Console.WriteLine("The length of the side of the square is {2}.  Area is {0}.  Perimeter is {1}.", area, perimeter, sidelength);
            //this will print "Area is {the variable area}. Perimeter is {the variable perimeter}.  0 corresponds with area, 1 corresponds with perimeter.

            //Square sqr2 = new Square();
            //sqr2.LengthOfSides = 3.3;
            //Console.WriteLine("Area is {0}.  Perimeter is {1}.", sqr2.GetArea(), sqr2.GetPerimeter());
            //We don't have to create a variable that does these actions - we can just use the methods we built!


            //Better yet, we can just do the following, using what we did on lin 29 of our Square class:
            Square sqr2 = new Square();

            sqr2.LengthOfSides = 3.3;
            sqr2.Print();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Rectangle rect         = new Rectangle(5, 10);
            var       rectPerimetr = rect.GetPerimetr();
            var       rectArea     = rect.GetArea();

            Console.WriteLine($"Rectangle Area: {rectArea} \n" +
                              $"Recatngle Perimetr: {rectPerimetr}");
            Console.WriteLine();


            Rectangle rect2          = new Square(2, 2);
            var       squarePerimetr = rect2.GetPerimetr();
            var       squareArea     = rect2.GetArea();

            Console.WriteLine($"Square Area: {squareArea} \n" +
                              $"Square Perimetr: {squarePerimetr}");
            Console.WriteLine();

            Circle circle = new Circle();

            circle.Radius = 5.63;
            var circlePerimetr = circle.GetPerimetr();
            var circleArea     = circle.GetArea();

            Console.WriteLine($"Circle Area: {circleArea} \n" +
                              $"Circle Perimetr: {circlePerimetr}");
            Console.WriteLine();

            Ellipse ellipse         = new Ellipse(12.1, 17.8);
            var     ellipsePerimetr = ellipse.GetPerimetr();
            var     ellipseArea     = ellipse.GetArea();

            Console.WriteLine($"Ellipse Area: {ellipseArea} \n" +
                              $"Ellipse Perimetr: {ellipsePerimetr}");
            Console.WriteLine();

            Triangle triangle = new Triangle();

            triangle.Height = 14;
            triangle.Side_A = 78;
            triangle.Side_B = 45;
            triangle.Side_C = 45;
            var trianglePerimetr = triangle.GetPerimetr();
            var triangleArea     = triangle.GetArea();

            Console.WriteLine($"Triangle Area: {triangleArea} \n" +
                              $"Triangle Perimetr: {trianglePerimetr}");
            Console.WriteLine();

            Triangle rightTriangle         = new RightTriangle(14, 15, 20.5);
            var      rightTrianglePerimetr = rightTriangle.GetPerimetr();
            var      rightTriangleArea     = rightTriangle.GetArea();

            Console.WriteLine($"Right Triangle Area: {rightTriangleArea} \n" +
                              $"Right Triangle Perimetr: {rightTrianglePerimetr}");
            Console.WriteLine();



            Console.ReadLine();
        }