Advertisement
Guest User

foursolids

a guest
Dec 15th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.97 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class foursolids {
  3.     public static void main(String[] args){
  4.         final double PI = 3.14159265;
  5.         double radius;
  6.         double height;
  7.         double area;
  8.         double volume;
  9.         double slant;
  10.         double radiusR;
  11.         char selection;
  12.         int totalcalc;
  13.         int calc = 0;
  14.         Scanner in = new Scanner(System.in);
  15.         System.out.println("Please enter 'a' do to cyclinder calculation, 'b' do to cone calculation, 'c' to do sphere calcalution, 'd' to do torus calculation, 'e' to exit the program :");
  16.         selection = in.next().charAt(0);
  17.         System.out.println();
  18.         switch (selection) {
  19.             case 'a':
  20.                 System.out.println("How many times do want to calculate? :");
  21.                 totalcalc = in.nextInt();
  22.                 System.out.println();
  23.                 while (calc<totalcalc) {
  24.                     System.out.println("Cyclinder calculation");
  25.                     System.out.println("Please enter radius :");
  26.                     radius = in.nextDouble();
  27.                     System.out.println("Please enter height :");
  28.                     height = in.nextDouble();
  29.                     area = 2 * PI * radius * (radius + height);
  30.                     volume = PI * radius * radius * height;
  31.                     area=Math.round(area*100.0)/100.0;
  32.                     volume=Math.round(volume*100.0)/100.0;
  33.                     System.out.println("Area for cyclinder is : " +area);
  34.                     System.out.println("Volume for cyclinder is : " +volume);
  35.                     System.out.println();
  36.                     calc++;
  37.                 }
  38.                 break;
  39.             case 'b':
  40.                 System.out.println("How many times do want to calculate? :");
  41.                 totalcalc = in.nextInt();
  42.                 System.out.println();
  43.                 while (calc<totalcalc) {
  44.                     System.out.println("Cone calculation");
  45.                     System.out.println("Please enter radius :");
  46.                     radius = in.nextDouble();
  47.                     System.out.println("Please enter height :");
  48.                     height = in.nextDouble();
  49.                     System.out.println("Please enter slant :");
  50.                     slant = in.nextDouble();
  51.                     area = PI * radius * (radius + slant);
  52.                     volume = 1/3 * radius * radius * PI * height;
  53.                     area=Math.round(area*100.0)/100.0;
  54.                     volume=Math.round(volume*100.0)/100.0;
  55.                     System.out.println("Area for cyclinder is : " +area);
  56.                     System.out.println("Volume for cyclinder is : " +volume);
  57.                     System.out.println();
  58.                     calc++;
  59.                 }
  60.                 break;
  61.             case 'c':
  62.                 System.out.println("How many times do want to calculate? :");
  63.                 totalcalc = in.nextInt();
  64.                 System.out.println();
  65.                 while (calc<totalcalc) {
  66.                     System.out.println("Sphere calculation");
  67.                     System.out.println("Please enter radius :");
  68.                     radius = in.nextDouble();
  69.                     area = 4 * PI * radius * radius;
  70.                     volume = 4/3 * PI * radius * radius * radius;
  71.                     area=Math.round(area*100.0)/100.0;
  72.                     volume=Math.round(volume*100.0)/100.0;
  73.                     System.out.println("Area for cyclinder is : " +area);
  74.                     System.out.println("Volume for cyclinder is : " +volume);
  75.                     System.out.println();
  76.                     calc++;
  77.                 }
  78.                 break;
  79.             case 'd':
  80.                 System.out.println("How many times do want to calculate? :");
  81.                 totalcalc = in.nextInt();
  82.                 System.out.println();
  83.                 while (calc<totalcalc) {
  84.                     System.out.println("Torus calculation");
  85.                     System.out.println("Please enter radius :");
  86.                     radius = in.nextDouble();
  87.                     System.out.println("Please enter radiusR :");
  88.                     radiusR = in.nextDouble();
  89.                     area = 4 * PI * PI * radiusR * radius;
  90.                     volume = 2 * PI * PI * radiusR * radius * radius;
  91.                     area=Math.round(area*100.0)/100.0;
  92.                     volume=Math.round(volume*100.0)/100.0;
  93.                     System.out.println("Area for cyclinder is : " +area);
  94.                     System.out.println("Volume for cyclinder is : " +volume);
  95.                     System.out.println();
  96.                     calc++;
  97.                 }
  98.                 break;
  99.             case 'e':
  100.                 System.out.println("You choose to exit the program");
  101.                 break;
  102.             default:
  103.                 System.out.println("Error! Please enter between 'a' , 'b' , 'c' , 'd' , 'e' only");
  104.                 break;
  105.         }
  106.         }
  107.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement