CurrencyConverter.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import java.util.*;
  2. public class CurrencyConverter {
  3. String currency1String;
  4. String currency2String;
  5. int amount;
  6. public static void main(String [] args){
  7. while(true){
  8. CurrencyConverter cc = new CurrencyConverter();
  9. Scanner kb = new Scanner(System.in);
  10. System.out.println("Convert the following currencies!\nUS Dollar - 'us'\nEuro - 'eu'\nBritish Pound = 'bPound'\nIndian Rupee = 'iRupee'\nAustralian Dollar = aDollar\n" +
  11. "Canadian Dollar = 'cDollar'\nSingapore Dollar = 'sDollar'\nSwiss Franc = 'sFranc'\nMalaysian Ringgit = 'mRinggit'\nJapanese Yen = 'jYen'\nChinese Yuan Renminbi = 'cYuan'");
  12. System.out.println("Please enter your base currency:");
  13. String currency1String = kb.nextLine();
  14. System.out.println("Please enter the amount:");
  15. int amount = kb.nextInt();
  16. kb.nextLine();
  17. System.out.println("Please enter your desired currency:");
  18. String currency2String = kb.nextLine();
  19. System.out.println(cc.convert(currency1String,currency2String,amount));
  20. }
  21. }
  22. public double getCurrency1(String currency1String){
  23. double currency1 = 0;
  24. switch(currency1String) {
  25. case "us" :
  26. currency1 = 1.00;
  27. break;
  28. case "eu" :
  29. currency1 = .94;
  30. break;
  31. case "bPound" :
  32. currency1 = .82;
  33. break;
  34. case "iRupee" :
  35. currency1 = 68.32;
  36. break;
  37. case "aDollar" :
  38. currency1 = 1.35;
  39. break;
  40. case "cDollar" :
  41. currency1 = 1.32;
  42. break;
  43. case "sDollar" :
  44. currency1 = 1.43;
  45. break;
  46. case "sFranc" :
  47. currency1 = 1.01;
  48. break;
  49. case "mRinggit" :
  50. currency1 = 4.47;
  51. break;
  52. case "jYen" :
  53. currency1 = 115.84;
  54. break;
  55. case "cYuan" :
  56. currency1 = 6.92;
  57. break;
  58. }
  59. return currency1;
  60. }
  61. public double getCurrency2(String currency2String){
  62. double currency2 = 0;
  63. switch(currency2String) {
  64. case "us" :
  65. currency2 = 1;
  66. break;
  67. case "eu" :
  68. currency2 = .94;
  69. break;
  70. case "bPound" :
  71. currency2 = .82;
  72. break;
  73. case "iRupee" :
  74. currency2 = 68.32;
  75. break;
  76. case "aDollar" :
  77. currency2 = 1.35;
  78. break;
  79. case "cDollar" :
  80. currency2 = 1.32;
  81. break;
  82. case "sDollar" :
  83. currency2 = 1.43;
  84. break;
  85. case "sFranc" :
  86. currency2 = 1.01;
  87. break;
  88. case "mRinggit" :
  89. currency2 = 4.47;
  90. break;
  91. case "jYen" :
  92. currency2 = 115.84;
  93. break;
  94. case "cYuan" :
  95. currency2 = 6.92;
  96. break;
  97. }
  98. return currency2;
  99. }
  100. public double convert(String currency1String, String currency2String, int amount ){
  101. double conversion;
  102. return conversion = (getCurrency2(currency2String)/getCurrency1(currency1String))*amount;
  103. }
  104. }