static void sphereChoice() { double radius; Console.WriteLine("Enter sphere radius in inches:"); radius = double.Parse(Console.ReadLine()); Circle disk1 = new Circle(radius); Sphere sphere = new Sphere(disk1); Console.WriteLine("Sphere volume: " + sphere.GetVolume()); Console.WriteLine("Sphere surface area: " + sphere.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; } }
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(); } } }