Advertisement
TomaszSoroka

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

Feb 17th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. import java.util.Locale;
  2. import java.util.Scanner;
  3.  
  4.     public class SpeedCalculator2 {
  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 [m], 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 minutes");
  15.             double timeInSeconds = scan.nextDouble();
  16.  
  17.             System.out.println("Your distance is: " + distanceInMeters + " meters");
  18.             System.out.println("Your time is: " + timeInSeconds + " minutes");
  19.  
  20.             double speedMs = distanceInMeters/timeInSeconds;
  21.             final double MS_TO_KMH_UNIT = 0.060;
  22.             double speedKmh = speedMs * MS_TO_KMH_UNIT;
  23.             System.out.println("Your speed in km/h: ");
  24.             System.out.println(speedKmh);
  25.         }
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement