
Untitled
By: a guest on
Aug 20th, 2012 | syntax:
None | size: 1.26 KB | hits: 15 | expires: Never
import java.util.Scanner;
public class Sphere {
public static void main(String[] args) {
//Declarations
int cont = 0;
double radiusNum;
double volume;
double output;
Calculations sc;
// Create scanner object
Scanner input = new Scanner(System.in);
System.out.println ("Welcome to Volume of Sphere calulator!");
//next line
System.out.println("");
//loop variable input
System.out.print("Would you like to calculate the volume now? Please enter 1 for Yes and 2 for No: ");
cont = input.nextInt();
//next line
System.out.println("");
// begin while loop
while(cont == 1)
{
//Prompt the user to enter the radius
System.out.print("Please enter the radius: ");
radiusNum = input.nextDouble();
sc = new Calculations ();
volume = sc.volumeOfSphere(radiusNum);
System.out.println("The volume of a sphere with a radius of " + radiusNum + " has a volume of " + volume);
//next line
System.out.println("");
//ask the user if he/she wants to enter another one
System.out.print("Would you like to calculate another volume? Please enter 1 for Yes, 2 for No: ");
cont = input.nextInt();
//next line
System.out.println("");
}
System.out.print ("Thank you!");
}
}