Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1.  
  2. import java.util.*;
  3.  
  4. /******************************************************************************
  5. * Author: Junaid
  6. * Date: 17/9/19
  7. * Purpose: Shape Calculator
  8. ******************************************************************************/
  9. public class ShapeCalculator
  10. {
  11. public static void main( String [] args)
  12. {
  13. Scanner sc = new Scanner(System.in);
  14. char userSelection;
  15.  
  16. System.out.println("Make a selection");
  17. System.out.println("Type 'c' for area of circle");
  18. System.out.println("Type 'r' for area of rectangle");
  19. System.out.println("Type 't' for area of triangle");
  20. System.out.println("Type 'e' to exit");
  21.  
  22. userSelection= sc.next().charAt(0);
  23.  
  24. switch(userSelection)
  25. {
  26.  
  27. case 'c':
  28. int diameter; int meters; int cm;
  29. double area; double mm; double length; double width; double base; double height; double radius;
  30. System.out.println("Please enter the diameter of the circle in cm");
  31. diameter = sc.nextInt();
  32. radius = (double)diameter/2;
  33. area = Math.PI*radius*radius;
  34. meters = (int)area/10000;
  35. cm = (int)area%10000;
  36. mm = (int)(area*10000%10000);
  37. mm = mm/100;
  38. System.out.println("The area of the circle is "+meters+"m^2, "+cm+"cm^2, "+mm+"mm^2.");
  39. break;
  40.  
  41. case 'r':
  42. System.out.println("Please Enter the length of the rectangle in cm");
  43. length = sc.nextDouble();
  44. System.out.println("Please Enter the width of the rectangle in cm");
  45. width = sc.nextDouble();
  46. area = length*width;
  47. meters = (int)area/10000;
  48. cm = (int)area%10000;
  49. mm = (int)(area*10000%10000);
  50. mm = mm/100;
  51. System.out.println("The area of the rectangle is "+meters+"m^2, "+cm+"cm^2, "+mm+"mm^2.");
  52. break;
  53.  
  54. case 't':
  55. System.out.println("Please enter the base of the triangle in mm");
  56. base = sc.nextDouble();
  57. System.out.println("Please enter the height of the triangle in mm");
  58. height = sc.nextDouble();
  59. area = 0.5*base*height;
  60. meters = (int)area/1000000;
  61. cm = (int)area/100%10000;
  62. mm = (int)((area*10)%1000);
  63. mm = mm/10;
  64. System.out.println("The area of the trianle is "+meters+"m^2, "+cm+"cm^2, "+mm+"mm^2.");
  65. break;
  66.  
  67. case 'e':
  68. System.out.println("ADIOS");
  69. break;
  70.  
  71. default:
  72. System.out.println("Please type in a correct option");
  73. break;
  74. }
  75.  
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement