Advertisement
Guest User

WorkCalculator.java

a guest
Jan 24th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class WorkCalculator {
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6. System.out.println("CALCULATE WORK OF AN OBJECT LIFTED - IN UNITED STATES SYSTEM OR SYSTEME INTERNATIONAL.");
  7. System.out.print("Enter the number of calculations you would like to do: ");
  8. int iterations = scan.nextInt();
  9. for(int i = 0; i < iterations; i++) {
  10. line();
  11. System.out.print("Enter 1 to use US System, or 2 to use SI system: ");
  12. int systemChoice = scan.nextInt();
  13. line();
  14. if(systemChoice == 2) {
  15. siSystem();
  16. }
  17. if(systemChoice == 1) {
  18. usSystem();
  19. }
  20. }
  21. System.out.println("\nThank you for calculating with Ethan.");
  22. }
  23. public static void siSystem() {
  24. Scanner scan = new Scanner(System.in);
  25. System.out.println("To calculate work (W) of an object lifted, we need to multiply the force by distance.");
  26. System.out.print("Enter the distance the object is lifted in meters: ");
  27. double distance = scan.nextDouble();
  28. //System.out.println("Now we need to calculate force.");
  29. System.out.print("Enter the mass of the object lifted in kilograms: ");
  30. double mass = scan.nextDouble();
  31. final double gravity = 9.8;
  32. double force = mass * gravity;
  33. System.out.println("Force = " + force + " Newtons");
  34. double work = force * distance;
  35. System.out.println("Work = " + work + " Joules");
  36. }
  37. // example: 10kg lifted 1.3 meters ---> F = 98 N, W = 127.4 J
  38.  
  39. public static void usSystem() {
  40. Scanner scan = new Scanner(System.in);
  41. System.out.println("To calculate work (W) of an object lifted, we need to multiply the force by distance.");
  42. System.out.print("Enter the distance the object is lifted in feet: ");
  43. double distance = scan.nextDouble();
  44. System.out.print("Enter the force of the object lifted in lbs (pounds): ");
  45. double force = scan.nextDouble();
  46. double work = force * distance;
  47. System.out.println("Work = " + work + " ft-lbs");
  48. }
  49. // example: 22 lb lifted 4.26 feet ---> 93.72 ft-lbs
  50. public static void line() {
  51. System.out.println("--------------------------------------------------");
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement