CurrencyConverter.java 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. public class CurrencyConverter {
  2. public double convertUserInput(double valueOfCurrencyHave, double valueOfCurrencyWant, int amount){
  3. double value = (valueOfCurrencyWant / valueOfCurrencyHave) * amount;
  4. String str = String.format("%.02f", value);
  5. double value2 = Double.parseDouble(str);
  6. return value2;
  7. }
  8. public double exchangeRate(String input){
  9. double value = 0;
  10. switch(input){
  11. case "USD":
  12. value = 1.00;
  13. break;
  14. case "EUR":
  15. value = 0.94;
  16. break;
  17. case "GBP":
  18. value = 0.82;
  19. break;
  20. case "INR":
  21. value = 68.32;
  22. break;
  23. case "AUD":
  24. value = 1.35;
  25. break;
  26. case "CAD":
  27. value = 1.32;
  28. break;
  29. case "SGD":
  30. value = 1.43;
  31. break;
  32. case "CHF":
  33. value = 1.01;
  34. break;
  35. case "MYR":
  36. value = 4.47;
  37. break;
  38. case "JPY":
  39. value = 115.84;
  40. break;
  41. case "CNY":
  42. value = 6.92;
  43. break;
  44. }
  45. return value;
  46. }
  47. }