Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class foursolids {
- public static void main(String[] args){
- final double PI = 3.14159265;
- double radius;
- double height;
- double area;
- double volume;
- double slant;
- double radiusR;
- char selection;
- int totalcalc;
- int calc = 0;
- Scanner in = new Scanner(System.in);
- 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 :");
- selection = in.next().charAt(0);
- System.out.println();
- switch (selection) {
- case 'a':
- System.out.println("How many times do want to calculate? :");
- totalcalc = in.nextInt();
- System.out.println();
- while (calc<totalcalc) {
- System.out.println("Cyclinder calculation");
- System.out.println("Please enter radius :");
- radius = in.nextDouble();
- System.out.println("Please enter height :");
- height = in.nextDouble();
- area = 2 * PI * radius * (radius + height);
- volume = PI * radius * radius * height;
- area=Math.round(area*100.0)/100.0;
- volume=Math.round(volume*100.0)/100.0;
- System.out.println("Area for cyclinder is : " +area);
- System.out.println("Volume for cyclinder is : " +volume);
- System.out.println();
- calc++;
- }
- break;
- case 'b':
- System.out.println("How many times do want to calculate? :");
- totalcalc = in.nextInt();
- System.out.println();
- while (calc<totalcalc) {
- System.out.println("Cone calculation");
- System.out.println("Please enter radius :");
- radius = in.nextDouble();
- System.out.println("Please enter height :");
- height = in.nextDouble();
- System.out.println("Please enter slant :");
- slant = in.nextDouble();
- area = PI * radius * (radius + slant);
- volume = 1/3 * radius * radius * PI * height;
- area=Math.round(area*100.0)/100.0;
- volume=Math.round(volume*100.0)/100.0;
- System.out.println("Area for cyclinder is : " +area);
- System.out.println("Volume for cyclinder is : " +volume);
- System.out.println();
- calc++;
- }
- break;
- case 'c':
- System.out.println("How many times do want to calculate? :");
- totalcalc = in.nextInt();
- System.out.println();
- while (calc<totalcalc) {
- System.out.println("Sphere calculation");
- System.out.println("Please enter radius :");
- radius = in.nextDouble();
- area = 4 * PI * radius * radius;
- volume = 4/3 * PI * radius * radius * radius;
- area=Math.round(area*100.0)/100.0;
- volume=Math.round(volume*100.0)/100.0;
- System.out.println("Area for cyclinder is : " +area);
- System.out.println("Volume for cyclinder is : " +volume);
- System.out.println();
- calc++;
- }
- break;
- case 'd':
- System.out.println("How many times do want to calculate? :");
- totalcalc = in.nextInt();
- System.out.println();
- while (calc<totalcalc) {
- System.out.println("Torus calculation");
- System.out.println("Please enter radius :");
- radius = in.nextDouble();
- System.out.println("Please enter radiusR :");
- radiusR = in.nextDouble();
- area = 4 * PI * PI * radiusR * radius;
- volume = 2 * PI * PI * radiusR * radius * radius;
- area=Math.round(area*100.0)/100.0;
- volume=Math.round(volume*100.0)/100.0;
- System.out.println("Area for cyclinder is : " +area);
- System.out.println("Volume for cyclinder is : " +volume);
- System.out.println();
- calc++;
- }
- break;
- case 'e':
- System.out.println("You choose to exit the program");
- break;
- default:
- System.out.println("Error! Please enter between 'a' , 'b' , 'c' , 'd' , 'e' only");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement