
Patrick B. answered 03/18/21
Math and computer tutor/teacher
using System;
public class Program
{
public int Menu()
{
int menuChoice=-1;
while ((menuChoice<0) || (menuChoice>3))
{
Console.WriteLine("******************************");
Console.WriteLine(" <1> CONE *");
Console.WriteLine(" <2> SPHERE *");
Console.WriteLine(" <3> CYLINDER *");
Console.WriteLine("***************************");
Console.WriteLine("");
Console.Write(" PLEASE INPUT SHAPE # :>");
string inbuff;
inbuff = Console.ReadLine();
menuChoice = Int32.Parse(inbuff);
}
return(menuChoice);
}
public void Go()
{
string inbuff;
int menuChoice = this.Menu();
double mass=-1;
while (mass<0)
{
Console.Write("Please input the Mass of the object :>");
inbuff = Console.ReadLine();
mass = Double.Parse(inbuff);
}
double radius = -1;
while (radius<0)
{
Console.Write("Please input the Radius of the Object :>");
inbuff = Console.ReadLine();
radius = Double.Parse(inbuff);
}
double height = -1;
if (menuChoice != 2)
{
while (height<0)
{
Console.Write("Please input the Height of the Object :>");
inbuff = Console.ReadLine();
height = Double.Parse(inbuff);
}
}
double volume = -1;
string strShape="?";
switch (menuChoice)
{
case 1:
{
volume = Math.PI / 3.00f * radius*radius * height;
strShape = " CONE ";
break;
}
case 2:
{
volume = Math.PI*4.00f/3 * radius*radius*radius;
strShape = " SPHERE ";
break;
}
case 3:
{
volume = Math.PI*radius*radius*height;
strShape = " CYLINDER ";
break;
}
}
Console.WriteLine("The mass of the " + strShape + " is " + mass);
Console.WriteLine(" The radius of the " + strShape + " is " + radius);
if (menuChoice!=2)
{
Console.WriteLine(" The height of the " + strShape + " is " + height);
}
Console.WriteLine(" The volume of the " + strShape + " is " + volume);
double density = mass/volume;
Console.WriteLine(" The density of the " + strShape + " is " + density);
}
public static void Main()
{
Program x = new Program();
x.Go();
}
}