martyz

MoneyConverter

Aug 2nd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.text.NumberFormat;
  3. import java.util.HashMap;
  4. import java.util.Locale;
  5. import java.util.Map;
  6. import java.util.Scanner;
  7.  
  8. /**
  9.  * Created by Losh17 on 25.7.2017 г..
  10.  */
  11. public class MoneyConverter {
  12.     public static void main(String[] args) {
  13.         Locale.setDefault(new Locale("us", "Us"));
  14.         Scanner console = new Scanner(System.in);
  15.         NumberFormat nf = new DecimalFormat("#.##");
  16.         Map<String, Double> map1map = new HashMap<String, Double>();
  17.         map1map.put("BGN", 1d);
  18.         map1map.put("USD", 1.79549d);
  19.         map1map.put("EUR", 1.95583d);
  20.         map1map.put("GBP", 2.53405d);
  21.  
  22.         Double moneyAmount = Double.parseDouble(console.nextLine());
  23.         String firstType = console.nextLine();
  24.         String secondType = console.nextLine();
  25.  
  26.         Double value1 = map1map.get(firstType);
  27.         Double value2 = map1map.get(secondType);
  28.         System.out.println(nf.format((value1 / value2) * moneyAmount) + " " + secondType);
  29.  
  30.  
  31.     }
  32. }
Add Comment
Please, Sign In to add comment