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
Loading
CrishPosted Nov 29, 2010, 6:28 AM
I think this is perfect answer for solution.
Hetalkumar KachhadiyaPosted Nov 3, 2010, 8:47 AM
//This enum will generalize your implementation for various classes required related to other different shapes.
//This interface will be used for defining the contract for various shapes
//As per the requirement specified by you ShapeFactory is the fourth class which is responsible for centralized creation of the object of type of class of the shape specified by the user
//Circle class
//Rectangle Class
//Cylinder class
If you need to add another shape (For example Cube) then you have define a corresponding class named 'Cube' which implements the 'IShape' interface and need to add a case for the same into the ShapeFactory class.
Please let me know if you have any queries in this reply.
Amit ChoudharyPosted Nov 3, 2010, 6:10 AM
Similarly create another classes for rectangle, cylinder etc. and in your fourth class create for method to create four type of shapes means creating the four instance in those methods. use switch case and on the basis of user selection call the appropriate method.
and show the details according to that.
hope you have an idea now.
Please mark "Do you like the answer?" if it helps you.