SHARE
TWEET

Untitled

a guest Oct 7th, 2017 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package L04DataTypesAndVariables.exercices;
  2.  
  3. import java.math.BigDecimal;
  4. import java.math.BigInteger;
  5. import java.math.RoundingMode;
  6. import java.text.DecimalFormat;
  7. import java.util.Scanner;
  8.  
  9. public class p11ConvertSpeedUnits {
  10.     public static void main(String[] args) {
  11.         Scanner scanner = new Scanner(System.in);
  12.  
  13.         float distanceInMeters = Float.parseFloat(scanner.nextLine());
  14.         float hours = Float.parseFloat(scanner.nextLine());
  15.         float minutes = Float.parseFloat(scanner.nextLine());
  16.         float seconds = Float.parseFloat(scanner.nextLine());
  17.  
  18.         SpeedConverter(distanceInMeters, hours, minutes, seconds);
  19.     }
  20.     public static void SpeedConverter(float dm, float h, float m, float s){
  21.  
  22.         DecimalFormat df = new DecimalFormat("#.###########");
  23.         df.setRoundingMode(RoundingMode.HALF_UP);
  24.  
  25.         float inSeconds = h * 3600f + m * 60f + s;
  26.  
  27.         float metersPerSecond = dm / inSeconds;
  28.         float kilometersPerHour = (dm / 1000f) / (inSeconds / 3600f);
  29.         float milesPerHour = (dm / 1609f) / (inSeconds / 3600f);
  30.  
  31.         String mPerSecondsString = Float.toString(metersPerSecond);
  32.         String kmPerHoursString = Float.toString(kilometersPerHour);
  33.         String milesPerHoursString = Float.toString(milesPerHour);
  34.  
  35.  
  36.         //System.out.println(mPerSecondsString.substring(0, Math.min(mPerSecondsString.length(), 8)));
  37.         //System.out.println(kmPerHoursString.substring(0, Math.min(kmPerHoursString.length(), 8)));
  38.         //System.out.println(milesPerHoursString.substring(0, Math.min(milesPerHoursString.length(), 8)));
  39.         //System.out.println();
  40. //
  41.         //System.out.println(df.format(metersPerSecond));
  42.         //System.out.println(df.format(kilometersPerHour));
  43.         //System.out.println(df.format(milesPerHour));
  44.         //System.out.println();
  45.  
  46.         //System.out.printf("%f%n", metersPerSecond);
  47.         //System.out.printf("%f%n", kilometersPerHour);
  48.         //System.out.printf("%f", milesPerHour);
  49.     }
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top