Advertisement
tchenkov

L02u12CurrencyConverter v1

Apr 23rd, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Uprajnenie02_12 {
  4.     public static void main(String[] args) {
  5.  
  6.         Scanner scan = new Scanner(System.in);
  7.  
  8.         double cash = Double.parseDouble(scan.nextLine());
  9.         String startingCurancy = scan.nextLine().toUpperCase();
  10.         String convertToCurancy = scan.nextLine().toUpperCase();
  11.         double cashConverted = Uprajnenie02_12.CashConverter(cash, startingCurancy, convertToCurancy);
  12.  
  13.         System.out.printf("%.2f %s", cashConverted, convertToCurancy);
  14.     }
  15.  
  16.     public static double CashConverter(double cash, String startCurancy, String endCurancy) {
  17.  
  18.         double toUsd = 1.79549;
  19.         double toEur = 1.95583;
  20.         double toGbp = 2.53405;
  21.  
  22.         if (cash == 0) {
  23.             return cash;
  24.         } else {
  25.             switch (startCurancy) {
  26.                 case "BGN":
  27.                     break;
  28.                 case "USD":
  29.                     cash = cash * toUsd;
  30.                     break;
  31.                 case "EUR":
  32.                     cash = cash * toEur;
  33.                     break;
  34.                 case "GBP":
  35.                     cash = cash * toGbp;
  36.             }
  37.  
  38.             switch (endCurancy) {
  39.                 case "BGN":
  40.                     break;
  41.                 case "USD":
  42.                     cash = cash / toUsd;
  43.                     break;
  44.                 case "EUR":
  45.                     cash = cash / toEur;
  46.                     break;
  47.                 case "GBP":
  48.                     cash = cash / toGbp;
  49.             }
  50.  
  51.             return cash;
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement