I'm trying to test this by converting the Yen and the USD both ways using an if-else statement. My output is always 0, and it seems like the if-else statement in the "conversion" method isn't doing what I want it to do.
import java.util.Scanner;
public class CurrencyConverter {
private Scanner sc;
private String currency;
private String currency2;
private int amount;
private int amount2;
public void getCurrency() {
System.out.println("Please enter the currency and the amount you want to convert.");
sc = new Scanner(System.in);
currency = sc.next();
amount = sc.nextInt();
System.out.println("Please enter the currency you want to convert to.");
currency2 = sc.next();
}
public void conversion() {
if(currency == "usd" && currency2 == "yen")
amount2 = amount * 146;
else if(currency == "yen" && currency2 == "usd")
amount2 = amount / 146;
System.out.println(amount2);
}
public static void main(String[] args) {
CurrencyConverter money = new CurrencyConverter();
money.getCurrency();
money.conversion();
}
}
I tried moving the logic in the "conversion" method into the "getCurrency" method with no success. I'm also open to other, more efficient ways of starting to build a program like this.