Advertisement
martyz

Metric Converter

Aug 7th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.Locale;
  3. import java.util.Map;
  4. import java.util.Scanner;
  5.  
  6.  
  7. public class UnitMeasureConverter {
  8.     public static void main(String[] args) {
  9.         Locale.setDefault(new Locale("us", "Us"));
  10.         Scanner console = new Scanner(System.in);
  11.         Map<String, Double> map1map = new HashMap<String, Double>();
  12.         map1map.put("m", 1d);
  13.         map1map.put("mm", 1000d);
  14.         map1map.put("cm", 100d);
  15.         map1map.put("in", 39.3700787d);
  16.         map1map.put("km", 0.001d);
  17.         map1map.put("ft", 3.2808399d);
  18.         map1map.put("yd", 1.0936133d);
  19.         map1map.put("mi", 0.000621371192d);
  20.  
  21.         Double input = Double.parseDouble(console.nextLine());
  22.         String firstType = console.nextLine();
  23.         String secondType = console.nextLine();
  24.  
  25.         Double value1 = map1map.get(firstType);
  26.         Double value2 = map1map.get(secondType);
  27.         Double result = (input / value1)  *  value2;
  28.  
  29.         System.out.printf("%.8f " + secondType, result);
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement