Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class WorkCalculator {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- System.out.println("CALCULATE WORK OF AN OBJECT LIFTED - IN UNITED STATES SYSTEM OR SYSTEME INTERNATIONAL.");
- System.out.print("Enter the number of calculations you would like to do: ");
- int iterations = scan.nextInt();
- for(int i = 0; i < iterations; i++) {
- line();
- System.out.print("Enter 1 to use US System, or 2 to use SI system: ");
- int systemChoice = scan.nextInt();
- line();
- if(systemChoice == 2) {
- siSystem();
- }
- if(systemChoice == 1) {
- usSystem();
- }
- }
- System.out.println("\nThank you for calculating with Ethan.");
- }
- public static void siSystem() {
- Scanner scan = new Scanner(System.in);
- System.out.println("To calculate work (W) of an object lifted, we need to multiply the force by distance.");
- System.out.print("Enter the distance the object is lifted in meters: ");
- double distance = scan.nextDouble();
- //System.out.println("Now we need to calculate force.");
- System.out.print("Enter the mass of the object lifted in kilograms: ");
- double mass = scan.nextDouble();
- final double gravity = 9.8;
- double force = mass * gravity;
- System.out.println("Force = " + force + " Newtons");
- double work = force * distance;
- System.out.println("Work = " + work + " Joules");
- }
- // example: 10kg lifted 1.3 meters ---> F = 98 N, W = 127.4 J
- public static void usSystem() {
- Scanner scan = new Scanner(System.in);
- System.out.println("To calculate work (W) of an object lifted, we need to multiply the force by distance.");
- System.out.print("Enter the distance the object is lifted in feet: ");
- double distance = scan.nextDouble();
- System.out.print("Enter the force of the object lifted in lbs (pounds): ");
- double force = scan.nextDouble();
- double work = force * distance;
- System.out.println("Work = " + work + " ft-lbs");
- }
- // example: 22 lb lifted 4.26 feet ---> 93.72 ft-lbs
- public static void line() {
- System.out.println("--------------------------------------------------");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement