123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- import java.util.*;
-
- public class CurrencyConverter {
- String currency1String;
- String currency2String;
- int amount;
-
- public static void main(String [] args){
- while(true){
-
- CurrencyConverter cc = new CurrencyConverter();
- Scanner kb = new Scanner(System.in);
- System.out.println("Convert the following currencies!\nUS Dollar - 'us'\nEuro - 'eu'\nBritish Pound = 'bPound'\nIndian Rupee = 'iRupee'\nAustralian Dollar = aDollar\n" +
- "Canadian Dollar = 'cDollar'\nSingapore Dollar = 'sDollar'\nSwiss Franc = 'sFranc'\nMalaysian Ringgit = 'mRinggit'\nJapanese Yen = 'jYen'\nChinese Yuan Renminbi = 'cYuan'");
- System.out.println("Please enter your base currency:");
- String currency1String = kb.nextLine();
- System.out.println("Please enter the amount:");
- int amount = kb.nextInt();
- kb.nextLine();
- System.out.println("Please enter your desired currency:");
- String currency2String = kb.nextLine();
- System.out.println(cc.convert(currency1String,currency2String,amount));
-
- }
-
- }
-
- public double getCurrency1(String currency1String){
- double currency1 = 0;
- switch(currency1String) {
- case "us" :
- currency1 = 1.00;
- break;
- case "eu" :
- currency1 = .94;
- break;
- case "bPound" :
- currency1 = .82;
- break;
- case "iRupee" :
- currency1 = 68.32;
- break;
- case "aDollar" :
- currency1 = 1.35;
- break;
- case "cDollar" :
- currency1 = 1.32;
- break;
- case "sDollar" :
- currency1 = 1.43;
- break;
- case "sFranc" :
- currency1 = 1.01;
- break;
- case "mRinggit" :
- currency1 = 4.47;
- break;
- case "jYen" :
- currency1 = 115.84;
- break;
- case "cYuan" :
- currency1 = 6.92;
- break;
-
- }
- return currency1;
- }
-
- public double getCurrency2(String currency2String){
- double currency2 = 0;
- switch(currency2String) {
- case "us" :
- currency2 = 1;
- break;
- case "eu" :
- currency2 = .94;
- break;
- case "bPound" :
- currency2 = .82;
- break;
- case "iRupee" :
- currency2 = 68.32;
- break;
- case "aDollar" :
- currency2 = 1.35;
- break;
- case "cDollar" :
- currency2 = 1.32;
- break;
- case "sDollar" :
- currency2 = 1.43;
- break;
- case "sFranc" :
- currency2 = 1.01;
- break;
- case "mRinggit" :
- currency2 = 4.47;
- break;
- case "jYen" :
- currency2 = 115.84;
- break;
- case "cYuan" :
- currency2 = 6.92;
- break;
-
- }
- return currency2;
- }
- public double convert(String currency1String, String currency2String, int amount ){
- double conversion;
- return conversion = (getCurrency2(currency2String)/getCurrency1(currency1String))*amount;
-
-
- }
-
- }
-
|