3
Reply

working on project with four classes (need serious help)

Kel Michael

Kel Michael

Nov 2 2010 4:18 PM
12.4k

create an application with four classes. three of the classes should contain data and behavior characteristics for circle, rectangle, and cylinder. the fourth class should allow the user to input a figure type from a menu of options. prompt for appropiate values based on the inputted figure type, instantiate an object of the type entered, and display characteristics about the object.
i have code for the circle but i cant figure out how to make the main class work with the other classes (circle, rectangle, and cylinder)
here is my code for the circle:
using System;

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

Answers (3)