Advertisement
veronikaaa86

SpeedUnits

Jan 28th, 2018
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.73 KB | None | 0 0
  1. package DataTypeAndVariables;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.text.DecimalFormat;
  7.  
  8. public class P11_ConvertSpeedUnits {
  9.     public static void main(String[] args) throws IOException {
  10.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  11.         DecimalFormat first = new DecimalFormat("#.#######");
  12.         DecimalFormat second = new DecimalFormat("#.######");
  13.         DecimalFormat third = new DecimalFormat("##.#####");
  14.         DecimalFormat fourth = new DecimalFormat("###.####");
  15.  
  16.         int distanceMeter = Integer.parseInt(reader.readLine());
  17.         int hours = Integer.parseInt(reader.readLine());
  18.         int minutes = Integer.parseInt(reader.readLine());
  19.         int seconds = Integer.parseInt(reader.readLine());
  20.  
  21.         int allMinutes = (hours * 60) + minutes;
  22.         int allSeconds = (allMinutes * 60) + seconds;
  23.         int allTime = hours * 3600 + minutes * 60 + seconds;
  24.  
  25.         float allHours = allSeconds * 0.000277777778f;
  26.  
  27.         float allKm = distanceMeter * 0.001f;
  28.  
  29.         float meterPerSeconds = (float)distanceMeter / allSeconds;
  30.         float kmPerHour = allKm / allHours;
  31.         float milePerHour = (distanceMeter / (float)1609) / (allTime / (float)3600);
  32.  
  33.         if (meterPerSeconds > 0 && meterPerSeconds < 1) {
  34.             System.out.println(first.format(meterPerSeconds));
  35.         }
  36.         if (kmPerHour > 0 && kmPerHour < 1) {
  37.             System.out.println(first.format(kmPerHour));
  38.         }
  39.         if (milePerHour > 0 && milePerHour < 1) {
  40.             System.out.println(first.format(milePerHour));
  41.         }
  42.  
  43.         if (meterPerSeconds > 0 && meterPerSeconds < 10) {
  44.             System.out.println(second.format(meterPerSeconds));
  45.         }
  46.         if (kmPerHour > 0 && kmPerHour < 10) {
  47.             System.out.println(second.format(kmPerHour));
  48.         }
  49.         if (milePerHour > 0 && milePerHour < 10) {
  50.             System.out.println(second.format(milePerHour));
  51.         }
  52.  
  53.         if (meterPerSeconds > 9 && meterPerSeconds < 100) {
  54.             System.out.println(third.format(meterPerSeconds));
  55.         }
  56.         if (kmPerHour > 9 && kmPerHour < 100) {
  57.             System.out.println(third.format(kmPerHour));
  58.         }
  59.         if (milePerHour > 9 && milePerHour < 100) {
  60.             System.out.println(third.format(milePerHour));
  61.         }
  62.  
  63.         if (meterPerSeconds > 99) {
  64.             System.out.println(fourth.format(meterPerSeconds));
  65.         }
  66.         if (kmPerHour > 99) {
  67.             System.out.println(fourth.format(kmPerHour));
  68.         }
  69.         if (milePerHour > 99) {
  70.             System.out.println(fourth.format(milePerHour));
  71.         }
  72.  
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement