# Untitled

a guest
Oct 7th, 2017
86
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);
34.
35.
36. //System.out.println(mPerSecondsString.substring(0, Math.min(mPerSecondsString.length(), 8)));