Alex
2012-04-28 20:05:57 UTC
Design a computer program to calculate the volume of either a box or cylinder using the formulas above. Display the name of the object (box or cylinder) and its volume. Design the program so that it loops for any number of geometric objects (boxes and/or cylinders), that is the program sequence needs to repeat for each set of input data to be processed. Do not be data specific.
For each iteration of your program you need to determine which geometric object to compute the volume for. A suggestion is to set up keys for each iteration such as 1 for box, 2 for cylinder, and 3 for no more data
Some sample data are as follows:
Geometric type (1 for box, 2 for cylinder, 3 for no more data)
THIS IS WHAT I GOT SO FAR BUT I KNOW THERE ARE A LOT OF ERRORS AND IM SO CONFUSED I WOULD REALLY APPRECIATE THE HELP. THANKS
import java.io.*;
import java.lang.*;
import java.text.*;
import java.util.*;
//Set up public class
public class calculation
{
//declare main() method
public static void main(String[] args) throws IOException
{
//Declare data types
float length,width,height,volume;
//set up input stream
Scanner readin = new Scanner(System.in);
//prompt for length
System.out.println("\n\n enter value for length");
//stream in length and convert to float
length = readin.nextFloat();
//prompt for width
System.out.println("\n\n enter value for width");
//stream in width and convert to float
width = readin.nextFloat();
//prompt for height
System.out.println("\n\n enter value for height");
//stream in height and convert to float
height = readin.nextFloat();
//Calculate results
volume of box= length*width*height;
//Declare data types
float length,radius,volume;
//set up input stream
//prompt for length
System.out.println("\n\n enter value for length");
//stream in length and convert to float
length = readin.nextFloat();
//prompt for radius
System.out.println("\n\n enter value for radius");
//stream in radius and convert to float
radius = readin.nextFloat();
//calculate results
volume of cylinder= 3.14(radius*radius*lenght)
//prepare data for out put display
System.out.print("\n\nThe results of the calcuations are\n\n\n");
System.out.print("the volume of the box is is:\t\t" + volume of box + "\n\n");
System.out.print("the volume ofthe cylinder is is:\t\t" + volume of cylinder + “\n\n”);
}//end main
}//end class