Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 20th, 2012  |  syntax: None  |  size: 1.26 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.util.Scanner;
  2.  
  3. public class Sphere {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.                 //Declarations
  8.                 int cont = 0;
  9.                 double radiusNum;
  10.                 double volume;
  11.                 double output;
  12.                 Calculations sc;
  13.  
  14.  
  15.                 // Create scanner object
  16.                 Scanner input = new Scanner(System.in);
  17.  
  18.                 System.out.println ("Welcome to Volume of Sphere calulator!");
  19.  
  20.                 //next line
  21.                 System.out.println("");
  22.  
  23.                 //loop variable input
  24.                 System.out.print("Would you like to calculate the volume now? Please enter 1 for Yes and 2 for No: ");
  25.                         cont = input.nextInt();
  26.  
  27.                 //next line
  28.                 System.out.println("");
  29.  
  30.  
  31.         // begin while loop
  32.         while(cont == 1)
  33.         {
  34.                 //Prompt the user to enter the radius
  35.                 System.out.print("Please enter the radius: ");
  36.                 radiusNum = input.nextDouble();
  37.  
  38.                 sc = new Calculations ();
  39.  
  40.                 volume = sc.volumeOfSphere(radiusNum);
  41.  
  42.                 System.out.println("The volume of a sphere with a radius of " + radiusNum + " has a volume of " + volume);
  43.  
  44.                 //next line
  45.                 System.out.println("");
  46.  
  47.                 //ask the user if he/she wants to enter another one
  48.                 System.out.print("Would you like to calculate another volume? Please enter 1 for Yes, 2 for No: ");
  49.                                 cont = input.nextInt();
  50.  
  51.                 //next line
  52.                 System.out.println("");
  53.         }
  54.  
  55.         System.out.print ("Thank you!");
  56. }
  57. }