TomaszSoroka

Speed Calculator (Time [s], Distance [m])

Feb 16th, 2019
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. import java.util.Locale;
  2. import java.util.Scanner;
  3.  
  4. public class SpeedCalculator {
  5.     public static void main(String[] args) {
  6.         //Create the Scanner
  7.         Scanner scan = new Scanner(System.in).useLocale(Locale.ENGLISH);
  8.         //enable to import from the user
  9.         //Scanner(System.in).useLocale(Locale.ENGLISH) allow to use . instead of ,
  10.         System.out.println("Speed Calculator (Time [s], Distance [m])");
  11.         System.out.println("-----------------------------------------");
  12.         System.out.println("Enter the distance in meters: ");
  13.         double distanceInMeters = scan.nextDouble();
  14.         System.out.println("Enter the time in seconds: ");
  15.         double timeInSeconds = scan.nextDouble();
  16.  
  17.         System.out.println("Your distance is " + distanceInMeters + " meters");
  18.         System.out.println("Your time is: " + timeInSeconds + " seconds");
  19.  
  20.         System.out.println("Your speed in m/s: ");
  21.         double speedMs = distanceInMeters/timeInSeconds;
  22.         final double MS_TO_KMH_UNIT = 3.6; //1 m/s = 3.6 km/h
  23.         double speedKmh = speedMs * MS_TO_KMH_UNIT;
  24.         System.out.println(speedMs);
  25.         System.out.println("Your speed in km/h: ");
  26.         System.out.println(speedKmh);
  27.     }
  28. }
Add Comment
Please, Sign In to add comment