CurrencyConverter.java 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. public class CurrencyConverter {
  2. public double rate(String typeOfCurrency){
  3. double rate = 0;
  4. if(typeOfCurrency.equals("USD")){
  5. rate = 1; //US dollar
  6. }
  7. if(typeOfCurrency.equals("EUR")){
  8. rate = 0.94; //euro
  9. }
  10. if(typeOfCurrency.equals("GBP")){
  11. rate = 0.82; //british pound
  12. }
  13. if(typeOfCurrency.equals("INR")){
  14. rate = 68.32; //indian rupee
  15. }
  16. if(typeOfCurrency.equals("AUD")){
  17. rate = 1.35; //australian dollar
  18. }
  19. if(typeOfCurrency.equals("CAD")){
  20. rate = 1.32; //canadian dollar
  21. }
  22. if(typeOfCurrency.equals("SGD")){
  23. rate = 1.43; //singapore dollar
  24. }
  25. if(typeOfCurrency.equals("CHF")){
  26. rate = 1.01; //swiss franc
  27. }
  28. if(typeOfCurrency.equals("MYR")){
  29. rate = 4.47; //malaysian ringgit
  30. }
  31. if(typeOfCurrency.equals("JPY")){
  32. rate = 115.84; //japanese yen
  33. }
  34. if(typeOfCurrency.equals("CNY")){
  35. rate = 6.92; //chinese yuan renminbi
  36. }
  37. return rate;
  38. }
  39. public double convertCurrency(String whereTo, String whereFrom, double amount){
  40. return rate(whereTo)*amount/rate(whereFrom);
  41. }
  42. }