Answer the question
In order to leave comments, you need to log in
How does Scanner scanner work as a method parameter?
Good afternoon. There is a problem on code decomposition. Spaghetti should be removed from the main method and scattered over other methods. One of them looks like this:
public static void convert(Scanner scanner, double moneyBeforeSalary) {
double rateUSD = 78.5;
double rateEUR = 85;
double rateJPY = 0.74;
System.out.println("Ваши сбережения: " + moneyBeforeSalary + " RUB");
System.out.println("В какую валюту хотите конвертировать? Доступные варианты: 1 - USD, 2 - EUR, 3 - JPY.");
int currency = scanner.nextInt();
if (currency == 1) {
System.out.println("Ваши сбережения в долларах: " + moneyBeforeSalary / rateUSD);
} else if (currency == 2) {
System.out.println("Ваши сбережения в евро: " + moneyBeforeSalary / rateEUR);
} else if (currency == 3) {
System.out.println("Ваши сбережения в иенах: " + moneyBeforeSalary / rateJPY);
} else {
System.out.println("Неизвестная валюта");
}
}
The convert method will be used to convert currencies. You will find the parameters for it in the precode. It should take as arguments the balance of the account and a variable of complex type scanner - this will avoid duplicating the code for reading the currency selection.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question