123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import java.util.*;
  2. public class CurrencyConverter {
  3. String curr1;
  4. String curr2;
  5. int total;
  6. public static void main(String[] args) {
  7. while(true){
  8. CurrencyConverter conv = new CurrencyConverter();
  9. Scanner kb = new Scanner(System.in);
  10. System.out.println("You may convert any of the following currencies:\n" +
  11. "US Dollar = us\nEuro = eu\nBritish Pound = bp\nIndian Rupee = ir\n" +
  12. "Australian Dollar = ad\nCanadian Dollar = cd\nSingapore Dollar = sd\n" +
  13. "Swiss Franc = sf\nMalaysian Ringit = mr\n Japanese Yen = jy\n" +
  14. "Chinese Yuan = cy");
  15. System.out.println("Please enter your first currency:");
  16. String curr1 = kb.nextLine();
  17. System.out.println("Amount?");
  18. int total = kb.nextInt();
  19. kb.nextLine();
  20. System.out.println("Enter the currency you'd like in return:");
  21. String curr2 = kb.nextLine();
  22. System.out.println(conv.convert(curr1, curr2, total));
  23. }
  24. }
  25. public double firstCurr(String curr1) {
  26. double firstCurr = 0.0;
  27. switch(curr1) {
  28. case "us" :
  29. firstCurr = 1.00;
  30. break;
  31. case "eu" :
  32. firstCurr = 0.94;
  33. break;
  34. case "bp" :
  35. firstCurr = 0.82;
  36. break;
  37. case "ir" :
  38. firstCurr = 68.32;
  39. break;
  40. case "ad" :
  41. firstCurr = 1.35;
  42. break;
  43. case "cd" :
  44. firstCurr = 1.32;
  45. break;
  46. case "sd" :
  47. firstCurr = 1.43;
  48. break;
  49. case "sf" :
  50. firstCurr = 1.01;
  51. break;
  52. case "mr" :
  53. firstCurr = 4.47;
  54. break;
  55. case "jy" :
  56. firstCurr = 115.84;
  57. break;
  58. case "cy" :
  59. firstCurr = 6.92;
  60. break;
  61. }
  62. return firstCurr;
  63. }
  64. public double secCurr(String curr2) {
  65. double secCurr = 0.0;
  66. switch(curr2) {
  67. case "us" :
  68. secCurr = 1.00;
  69. break;
  70. case "eu" :
  71. secCurr = 0.94;
  72. break;
  73. case "bp" :
  74. secCurr = 0.82;
  75. break;
  76. case "ir" :
  77. secCurr = 68.32;
  78. break;
  79. case "ad" :
  80. secCurr = 1.35;
  81. break;
  82. case "cd" :
  83. secCurr = 1.32;
  84. break;
  85. case "sd" :
  86. secCurr = 1.43;
  87. break;
  88. case "sf" :
  89. secCurr = 1.01;
  90. break;
  91. case "mr" :
  92. secCurr = 4.47;
  93. break;
  94. case "jy" :
  95. secCurr = 115.84;
  96. break;
  97. case "cy" :
  98. secCurr = 6.92;
  99. break;
  100. }
  101. return secCurr;
  102. }
  103. public double convert(String curr1, String curr2, int total) {
  104. double converted;
  105. return converted = (secCurr(curr2) * total)/firstCurr(curr1);
  106. }
  107. }