I am currently working on a simple java project that converts a selected currency, to a selected currency. I seem to be having a problem with the if/elseif statements because whenever I run the method to do the appropriate maths, the original variable stays the same. I originally tried to run a boolean operation with a string entered by the user("USD", "EUR") via the .equals method but I ran into the same issue.
Here is a portion of my method where I think the error arises(whole method for clarity added**):
public double doMath(double USD, double CAD, double GBP, double YEN, double EUR, double CHF, int ogCurrency, int newCurrency, double howMuch){
if (ogCurrency == 2){
if (newCurrency == 1){
howMuch = howMuch * CAD;
}
else if (newCurrency == 3){
howMuch = howMuch * GBP;
}
else if (newCurrency == 6){
howMuch = howMuch * YEN;
}
else if (newCurrency == 4){
howMuch = howMuch * EUR;
}
else if (newCurrency == 5){
howMuch = howMuch * CHF;
}
}
else if (ogCurrency == 1){
howMuch = howMuch / CAD;
if (newCurrency == 2){
howMuch = howMuch * USD;
}
else if (newCurrency == 3){
howMuch = howMuch * GBP;
}
else if (newCurrency == 6){
howMuch = howMuch * YEN;
}
else if (newCurrency == 4){
howMuch = howMuch * EUR;
}
else if (newCurrency == 5){
howMuch = howMuch * CHF;
}
}
else if (ogCurrency == 3){
howMuch = howMuch / GBP;
if (newCurrency == 1){
howMuch = howMuch * USD;
}
else if (newCurrency == 2){
howMuch = howMuch * CAD;
}
else if (newCurrency == 6){
howMuch = howMuch * YEN;
}
else if (newCurrency == 4){
howMuch = howMuch * EUR;
}
else if (newCurrency == 5){
howMuch = howMuch * CHF;
}
}
else if (ogCurrency == 6){
howMuch = howMuch / YEN;
if (newCurrency == 1){
howMuch = howMuch * USD;
}
else if (newCurrency == 3){
howMuch = howMuch * GBP;
}
else if (newCurrency == 2){
howMuch = howMuch * CAD;
}
else if (newCurrency == 4){
howMuch = howMuch * EUR;
}
else if (newCurrency == 5){
howMuch = howMuch * CHF;
}
}
else if (ogCurrency == 4){
howMuch = howMuch / EUR;
if (newCurrency == 1){
howMuch = howMuch * USD;
}
else if (newCurrency == 3){
howMuch = howMuch * GBP;
}
else if (newCurrency == 6){
howMuch = howMuch * YEN;
}
else if (newCurrency == 2){
howMuch = howMuch * CAD;
}
else if (newCurrency == 5){
howMuch = howMuch * CHF;
}
}
else if (ogCurrency == 5){
howMuch = howMuch / CHF;
if (newCurrency == 1){
howMuch = howMuch * USD;
}
else if (newCurrency == 3){
howMuch = howMuch * GBP;
}
else if (newCurrency == 6){
howMuch = howMuch * YEN;
}
else if (newCurrency == 4){
howMuch = howMuch * EUR;
}
else if (newCurrency == 2){
howMuch = howMuch * CAD;
}
}
/*else{
System.out.println("Something didn't add up");
}*/
return howMuch;
&& main if that will help
public static void main(String[] args) {
double USD = 1.00;
double CAD = 1.31; // canadian dollar
double YEN = 101.20; // jap yen
double GBP = 0.77; // british pound
double EUR = 0.89; // euro
double CHF = 0.97; // swiss franc
// initiate object of class
CurrencyConverter converterBasic;
// assigning default values to fractionsBasic
converterBasic = new CurrencyConverter(1, 1, 1.00);
// new scanner for fetching input, premade class Scanner creating object in to run method(parameters/gets input from System.in)
Scanner in = new Scanner(System.in);
System.out.print("Enter your starting currency #(1: CAD, 2: USD, 3: GBP, 4: EUR, 5: CHF, 6: YEN): ");
int ogCurrency;
ogCurrency = in.nextInt();
converterBasic.setOgCurrency(ogCurrency);
System.out.print("Enter your desired currency please #(1: CAD, 2: USD, 3: GBP, 4: EUR, 5: CHF, 6: YEN): ");
int newCurrency;
newCurrency = in.nextInt();
converterBasic.setNewCurrency(newCurrency);
System.out.print("Enter how much cash you have please: ");
double howMuch;
howMuch = in.nextDouble();
converterBasic.setHowMuch(howMuch);
// use appropriate methods defined in class to compute conversion
converterBasic.doMath(USD, CAD, GBP, YEN, EUR, CHF, ogCurrency, newCurrency, howMuch);
// print appropriate output formatted using printf
System.out.printf(converterBasic.toString());
Does anyone spot what the problem with this by chance, it's definitely right under my nose. Thanks so much in advance, I look forward to hearing your wisdom.