123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- import java.util.*;
-
- public class CurrencyConverter {
-
- String curr1;
- String curr2;
- int total;
-
- public static void main(String[] args) {
-
- while(true){
-
- CurrencyConverter conv = new CurrencyConverter();
- Scanner kb = new Scanner(System.in);
-
- System.out.println("You may convert any of the following currencies:\n" +
- "US Dollar = us\nEuro = eu\nBritish Pound = bp\nIndian Rupee = ir\n" +
- "Australian Dollar = ad\nCanadian Dollar = cd\nSingapore Dollar = sd\n" +
- "Swiss Franc = sf\nMalaysian Ringit = mr\n Japanese Yen = jy\n" +
- "Chinese Yuan = cy");
- System.out.println("Please enter your first currency:");
- String curr1 = kb.nextLine();
- System.out.println("Amount?");
- int total = kb.nextInt();
- kb.nextLine();
- System.out.println("Enter the currency you'd like in return:");
- String curr2 = kb.nextLine();
- System.out.println(conv.convert(curr1, curr2, total));
-
-
- }
- }
-
- public double firstCurr(String curr1) {
-
- double firstCurr = 0.0;
-
- switch(curr1) {
-
- case "us" :
- firstCurr = 1.00;
- break;
- case "eu" :
- firstCurr = 0.94;
- break;
- case "bp" :
- firstCurr = 0.82;
- break;
- case "ir" :
- firstCurr = 68.32;
- break;
- case "ad" :
- firstCurr = 1.35;
- break;
- case "cd" :
- firstCurr = 1.32;
- break;
- case "sd" :
- firstCurr = 1.43;
- break;
- case "sf" :
- firstCurr = 1.01;
- break;
- case "mr" :
- firstCurr = 4.47;
- break;
- case "jy" :
- firstCurr = 115.84;
- break;
- case "cy" :
- firstCurr = 6.92;
- break;
- }
-
- return firstCurr;
-
- }
-
- public double secCurr(String curr2) {
- double secCurr = 0.0;
-
-
- switch(curr2) {
-
- case "us" :
- secCurr = 1.00;
- break;
- case "eu" :
- secCurr = 0.94;
- break;
- case "bp" :
- secCurr = 0.82;
- break;
- case "ir" :
- secCurr = 68.32;
- break;
- case "ad" :
- secCurr = 1.35;
- break;
- case "cd" :
- secCurr = 1.32;
- break;
- case "sd" :
- secCurr = 1.43;
- break;
- case "sf" :
- secCurr = 1.01;
- break;
- case "mr" :
- secCurr = 4.47;
- break;
- case "jy" :
- secCurr = 115.84;
- break;
- case "cy" :
- secCurr = 6.92;
- break;
- }
-
- return secCurr;
-
- }
-
- public double convert(String curr1, String curr2, int total) {
- double converted;
- return converted = (secCurr(curr2) * total)/firstCurr(curr1);
- }
-
-
- }
-
-
|