Esempio n. 1
19
        public void Area_should_be_side_length_times_two()
        {
            var square = new Square {SideLength = 5};
            var area = square.GetArea();

            Assert.AreEqual(25, area);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Point centreRect = new Point(1, 1);
            Point centreSquare = new Point(0, 0);

            Rectangle rect = new Rectangle(3, 5, centreRect);
            Square square = new Square(2, centreSquare);
            Ellipse ellipse = new Ellipse(2, 1, centreSquare);

            Console.WriteLine(rect.ToString());
            Console.WriteLine(rect.GetArea() + " " + rect.GetPerimeter());

            Console.WriteLine(square.ToString());
            Console.WriteLine(square.GetArea() + " " + square.GetPerimeter());

            Console.WriteLine(ellipse.ToString());
            Console.WriteLine(ellipse.GetArea() + " " + ellipse.GetPerimeter());
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Square square1 = new Square(5);

            double area = square1.GetArea();

            Console.WriteLine(area);
            double perimeter = square1.GetPerimeter();

            Console.WriteLine(perimeter);
            square1.Setside(15);
            double sideValue = square1.GetSide();

            Console.WriteLine(sideValue);

            Circle circle1 = new Circle(2);

            double areaCircle = circle1.GetArea();

            Console.WriteLine(areaCircle);
            double circumferenceCircle = circle1.GetCircumference();

            Console.WriteLine(circumferenceCircle);
            circle1.SetRadius(15);
            double radiusValue = circle1.GetRadius();

            Console.WriteLine(radiusValue);

            Triangle triangle1 = new Triangle(2, 3, 5);

            double areatriangle = triangle1.GetArea();

            Console.WriteLine(areatriangle);
            double perimetertriangle = triangle1.GetPerimeter();

            Console.WriteLine(perimetertriangle);
            triangle1.SetSideA(10);
            Console.WriteLine(triangle1.GetSideA());
        }
        public static void Main()
        {
            string keepGoing = "";

            while (keepGoing == "")
            {
                Console.WriteLine("Hi! Lets get geometric with shapes. Type in any one of the following shapes to calculate its standard dimensions.");
                Console.WriteLine("(Rectangle, Square, Circle) ...more to come...");
                string userShape = Console.ReadLine();
                // User chose Rectangle
                if (userShape == "Rectangle" || userShape == "rectangle")
                {
                    Console.WriteLine("Type in the length of the rectangle:");
                    int userLength = int.Parse(Console.ReadLine());
                    Console.WriteLine("Now type in the width of the rectangle:");
                    int       userWidth = int.Parse(Console.ReadLine());
                    Rectangle uRect     = new Rectangle(userLength, userWidth);
                    int       result    = uRect.GetArea();
                    bool      squa      = uRect.IsSquare();
                    Console.WriteLine("The area is : " + result);
                    Console.WriteLine("Is it a square? " + squa);
                    if (squa)
                    {
                        Console.WriteLine("Since your dimensions are that of a square...\n");
                        Console.WriteLine("Let's transform your \"square\" in to a cube...\n");
                        Box uBox   = new Box(uRect);
                        int resVol = uBox.GetVolume();
                        int resSur = uBox.GetSurfaceArea();
                        Console.WriteLine("The volume of your cube is: " + resVol);
                        Console.WriteLine("The surface area of your cube is: " + resSur);
                        //Prompt to keep while loop going (keep playing)
                        Console.WriteLine("\nType Enter to try again or type \"s\" to Quit.");
                        keepGoing = Console.ReadLine();
                    }
                    else
                    {
                        Console.WriteLine("Lets transform you rectangle in to a box...\n");
                        Box uBox   = new Box(uRect);
                        int resVol = uBox.GetVolume();
                        int resSur = uBox.GetSurfaceArea();
                        Console.WriteLine("The volume of your box is: " + resVol);
                        Console.WriteLine("The surface area of your box is: " + resSur);
                        //Prompt to keep while loop going (keep playing)
                        Console.WriteLine("\nType Enter to try again or type \"s\" to Quit.");
                        keepGoing = Console.ReadLine();
                    }
                }
                // User chose Square
                else if (userShape == "Square" || userShape == "square")
                {
                    Console.WriteLine("Type in the length of the sides: ");
                    int    userLength = int.Parse(Console.ReadLine());
                    Square uSquare    = new Square(userLength);
                    int    resArea    = uSquare.GetArea();
                    Console.WriteLine("\nThe area of your square is: " + resArea);
                    Console.WriteLine("Now let's transform you square in to a cube...\n");
                    Cube uCube  = new Cube(uSquare);
                    int  resVol = uCube.GetVolume();
                    int  resSur = uCube.GetSurfaceArea();
                    Console.WriteLine("The volume of your cube is: " + resVol);
                    Console.WriteLine("The Surface Area of your Cube is: " + resSur);
                    //Prompt to keep while loop going (keep playing)
                    Console.WriteLine("\nType Enter to try again or type \"s\" to Quit.");
                    keepGoing = Console.ReadLine();
                }
                // User chose Circle
                else if (userShape == "Circle" || userShape == "circle")
                {
                    Console.WriteLine("Type in the length of the radius: ");
                    int    userRadius = int.Parse(Console.ReadLine());
                    Circle uCircle    = new Circle(userRadius);
                    double resCircum  = uCircle.GetCircumference();
                    double resArea    = uCircle.GetArea();
                    Console.WriteLine("\nThe Circumference of your Cirlce is: " + resCircum);
                    Console.WriteLine("The Area of you Circle is: " + resArea);
                    Console.WriteLine("Now let's transform your Circle in to a Sphere...");
                    Sphere newSphere = new Sphere(uCircle);
                    double resVol    = newSphere.GetVolume();
                    double resSur    = newSphere.GetSurfaceArea();
                    Console.WriteLine("The Volume of your Sphere is: " + resVol);
                    Console.WriteLine("The Surface Area of your Sphere is: " + resSur);
                    //Prompt to keep while loop going (keep playing)
                    Console.WriteLine("\nTap enter to try again or type \"s\" to Quit.");
                    keepGoing = Console.ReadLine();
                }
            }
        }