Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Scanner;
- /*** Created by AiKiHack on 13-03-2017 02:21 in project dataTypes11032017 ***/
- public class p12ce_CurrencyConverter {
- static Scanner consolein = new Scanner(System.in);
- static Map<String, Double> rates = new HashMap<String, Double>();
- public static void main(String[] args) {
- rates.put("BGN", new Double(1.0));
- rates.put("USD", new Double(1.79549));
- rates.put("EUR", new Double(1.95583));
- rates.put("GBP", new Double(2.53405));
- double inputSum = Double.parseDouble(consolein.nextLine());
- String currIn = consolein.nextLine();
- String currOut = consolein.nextLine();
- if (rates.get(currIn) == null){newCurrency(currIn);} // TODO check HashMap not exists(key)
- if (rates.get(currOut) == null){newCurrency(currOut);} // TODO check HashMap not exists(key)
- double result = inputSum * rates.get(currIn) / rates.get(currOut);
- System.out.printf("%.2f %s", result, currOut);
- }
- public static void newCurrency(String currCode) {
- System.out.printf("Currency rate for %s unavailable! \n To Add new rate type 'YES' \n", currCode);
- String answer = consolein.nextLine();
- double newRate;
- if (answer.equals("YES")){
- System.out.printf("Add rate for %s : \n", currCode);
- newRate = Double.parseDouble(consolein.nextLine());
- rates.put(currCode, new Double(newRate));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment