Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. /*******************************************
  4. * Author: Ryan Forster 19145178 *
  5. * Purpose: To calculate the area of shapes *
  6. * Date: 15/03/2018 *
  7. *******************************************/
  8.  
  9. public class ShapeCalculator
  10. {
  11. public static void main( String [] args)
  12. {
  13. circleCalc();
  14.  
  15. rectangleCalc();
  16.  
  17. triangleCalc();
  18. }
  19.  
  20. public static void circleCalc()
  21. {
  22. int circDiameter;
  23.  
  24. double area;
  25.  
  26. circDiameter = inputInteger("Enter diameter");
  27.  
  28. area = calcCircArea(circDiameter);
  29.  
  30. getDimensions(area);
  31.  
  32. }
  33.  
  34. public static void rectangleCalc()
  35. {
  36. double recLength, recWidth;
  37.  
  38. recLength = inputReal("Enter length");
  39.  
  40. recWidth = inputReal("Enter width");
  41.  
  42. area = calcRecArea(recLength, recWidth);
  43.  
  44. getDimensions(area);
  45.  
  46. }
  47.  
  48. public static void triangleCalc()
  49. {
  50. double triBase, triHeight;
  51.  
  52. triBase = inputReal("Enter base");
  53.  
  54. triHeight = inputReal("Enter height");
  55.  
  56. area = calcTriArea(triBase, triHeight);
  57.  
  58. getDimensions(area);
  59.  
  60. }
  61.  
  62. public static double calcCircArea(int circDiameter)
  63. {
  64.  
  65. double radius, circSum, circArea;
  66.  
  67. radius = (double)circDiameter / 2;
  68.  
  69. circSum = radius * radius;
  70.  
  71. circArea = circSum * Math.PI;
  72.  
  73. return circArea;
  74.  
  75. }
  76.  
  77. public static double calcRecArea(double recLength, double recWidth)
  78. {
  79. double recArea;
  80.  
  81. recArea = recLength * recWidth;
  82.  
  83. return recArea;
  84.  
  85. }
  86.  
  87. public static double calcTriArea(double triBase, double triHeight)
  88. {
  89. double triArea;
  90.  
  91. triArea = triBase * triHeight / 2;
  92.  
  93. triArea = triArea / 100;
  94.  
  95. return triArea;
  96.  
  97. }
  98.  
  99. public static void getDimensions(double area)
  100. {
  101. int getM, getCM;
  102.  
  103. double getMM;
  104.  
  105. getMM = (area - (int)area) * 100;
  106.  
  107. getM = (int)area / 10000;
  108.  
  109. getCM = (int)area - getM * 10000;
  110.  
  111. System.out.println("The area of your shape is " + getM + "m^2 " + getCM + "cm^2 " + getMM + "mm^2");
  112.  
  113. }
  114.  
  115. public static int inputInteger(String msg);
  116. {
  117. int output;
  118.  
  119. output = sc.nextInt();
  120.  
  121. System.out.println(msg);
  122.  
  123. return output;
  124.  
  125. }
  126.  
  127. public static double inputReal(String msg);
  128. {
  129. double output;
  130.  
  131. output = sc.nextDouble();
  132.  
  133. System.out.printlm(msg);
  134.  
  135. return output;
  136.  
  137. }
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement