Advertisement
LenCristoff

Currency Converter Java

Jul 11th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class p12_CurrencyConverter {
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6.  
  7. double amount = Double.parseDouble(scan.nextLine());
  8. String inputCurrency = scan.nextLine();
  9. String outputCurrency = scan.nextLine();
  10.  
  11. double bgn = 0;
  12. double exchangeResult = 0;
  13.  
  14. switch (inputCurrency) {
  15. case "BGN":
  16. bgn = amount;
  17. break;
  18. case "USD":
  19. bgn = amount * 1.79549;
  20. break;
  21. case "EUR":
  22. bgn = amount * 1.95583;
  23. break;
  24. case "GBP":
  25. bgn = amount * 2.53405;
  26. default:
  27. System.out.println("Error!");
  28. break;
  29. }
  30. switch (outputCurrency) {
  31. case "BGN":
  32. exchangeResult = bgn;
  33. break;
  34. case "USD":
  35. exchangeResult = bgn / 1.79549;
  36. break;
  37. case "EUR":
  38. exchangeResult = bgn / 1.95583;
  39. break;
  40. case "GBP":
  41. exchangeResult = bgn / 2.53405;
  42. break;
  43. default:
  44. System.out.println("Error!");
  45. break;
  46. }
  47. System.out.printf("%.2f %s", exchangeResult, outputCurrency);
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement