Exemplo n.º 1
0
        static void cubeChoice()
        {
            int length;

            Console.WriteLine("Enter cube side length in inches:");
            length = int.Parse(Console.ReadLine());
            Rectangle side1 = new Rectangle(length, length);
            Cube      cube  = new Cube(side1);

            Console.WriteLine("Cube volume: " + cube.GetVolume());
            Console.WriteLine("Cube surface area: " + cube.GetSurfaceArea());

            Console.WriteLine("1: Another shape, 2: Exit program");
            int exitChoice;

            exitChoice = int.Parse(Console.ReadLine());
            if (exitChoice == 1)
            {
                Main();
            }
            else if (exitChoice == 2)
            {
                return;
            }
        }
Exemplo n.º 2
0
        public static void Main()
        {
            Console.WriteLine("This program does some math with certain shapes.");
            Console.WriteLine("To start with, specify a shape. Choose from circle, cube, rectangle or sphere.");
            string input = Console.ReadLine();

            switch (input.ToLower())
            {
            case "circle":
            {
                Console.WriteLine("Input circle radius (must be a whole number, digits only)");
                Circle newCircle = new Circle(circleRadius: Convert.ToInt32(Console.ReadLine()));
                Console.WriteLine($"The diameter of this circle is {newCircle.getDiameter().ToString()} and the circumference is {newCircle.getCircumference().ToString()}.");
                break;
            }

            case "cube":
            {
                Console.WriteLine("First, put in a value for the length and width of each face of the cube (single whole number, digits only)");
                int  tempFace = Convert.ToInt32(Console.ReadLine());
                Cube newCube  = new Cube(new Rectangle(tempFace, tempFace));
                Console.WriteLine($"The volume of the cube is {newCube.GetVolume().ToString()} and the surface area is {newCube.GetSurfaceArea().ToString()}. ");
                break;
            }

            case "rectangle":
            {
                Console.WriteLine("Input length (whole number, digits only)");
                int tempLength = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Input width (whole number, digits only)");
                int       tempWidth    = Convert.ToInt32(Console.ReadLine());
                Rectangle newRectangle = new Rectangle(tempLength, tempWidth);
                Console.WriteLine($"The area of the rectangle is {newRectangle.GetArea().ToString()} and it {(newRectangle.IsSquare() ? "is" : "is not")} a square.");
                break;
            }

            case "sphere":
            {
                Console.WriteLine("Input the radius (whole number, digits only)");
                Sphere newSphere = new Sphere(new Circle(Convert.ToInt32(Console.ReadLine())));
                Console.WriteLine($"The volume of the sphere is {newSphere.getVoulume().ToString()} and the surface area is {newSphere.getSurfaceArea().ToString()}.");
                break;
            }

            default:
                Console.WriteLine("I'm sorry, Dave, I'm afraid I can't do that.");
                break;
            }
        }
        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();
                }
            }
        }