Guest User

Untitled

a guest
Feb 16th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. package mathCalc;
  2. public class MathCalc {
  3. //Custom function
  4. public static void Volcalc(double _radius) {
  5. double volume = 4.0 / 3.0 * Math.PI * _radius * _radius * _radius;
  6. say("The vloume of the sphere of radius"+_radius+" is "+volume);
  7. }
  8. /*calcVolCyl
  9. * calculate the volume of a cylinder based on
  10. * height and radius
  11. */
  12. static void CalcVolCyl(double radius, double height) {
  13. double volume = Math.PI * radius * radius * height;
  14. //decide if the Vol is bigger enough to be a pool
  15. if ((volume > 5) && (height <= 1.5)) {
  16. //only runs if the condition above is true
  17. say("The volume of your pool is "+volume);
  18. }
  19. else if ((volume > 0.1) && (height <= 0.3)) {
  20. //only runs if the condition above is true
  21. say("The volume of your bucket is "+volume);
  22. }
  23. else if ((volume >= 50) && (volume <= 1000)) {
  24. //only checks if the other conditions are not true
  25. say("The volume of your cystern is "+volume);
  26. }
  27.  
  28. else {
  29. //The default case, If nothing else is true
  30. say("The volume of your whatever is "+volume);
  31. }
  32. }
  33.  
  34. /*say function
  35. * The say function will output a string msg to the console
  36. *
  37. */
  38. public static void say(String msg) {
  39. System.out.println(msg);
  40. }
  41.  
  42. public static void main(String[] args) {
  43. double radius = 0.5;
  44. double height = 0.2;
  45. //Volcalc(radius);
  46. CalcVolCyl(radius , height);
  47. height++;
  48. CalcVolCyl(radius , height);
  49. CalcVolCyl(500, height + 2.7);
  50. CalcVolCyl(4, 1.3);
  51. CalcVolCyl(2, 1.5);
  52. }
  53.  
  54. }
Add Comment
Please, Sign In to add comment