C# Im only on chapter 5 so please no advanced stuff like factory classes. Also p
ID: 3568379 • Letter: C
Question
C# Im only on chapter 5 so please no advanced stuff like factory classes. Also please comment all important areas if you can so I can get a better understanding of what to do. If someone can just get it started ill finish it. Im unsure how to get the enum switch to(which is in Main) "talk to" the other classes. Create an app with four classes. Three of the classes should contain data and behavior characteristics for circle, rectangle and cylinder. The forth class (Main) should allow the user to input a figure type from a menu of options (enum with switch). Prompt the user for appropriate values based on the inputted figure type, instantiate an object of the type entered and display characteristics about the object. Use the appropriate constructors, methods and properties. Thanks
Explanation / Answer
Program to Create an app with four classes :
public class Sphere
{
// obtain radius from user and display volume of sphere
public void DetermineSphereVolume()
{
Console.Write( "Enter radius of sphere: " );
double radius = Convert.ToDouble( Console.ReadLine() );
Console.WriteLine( "Volume is {0:F3}", SphereVolume( radius ) );
} // end method DetermineSphereVolume
// calculate and return sphere volume
public double SphereVolume( double radius )
{
double volume = ( 4.0 / 3.0 ) * Math.PI * Math.Pow( radius, 3 );
return volume;
} // end method SphereVolume
} // end class Sphere
// Calculate the volume of a sphere.
public class SphereTest
{
// application starting point
public static void Main( string[] args )
{
Sphere mySphere = new Sphere();
mySphere.DetermineSphereVolume();
} // end Main
} // end class SphereTest
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.