public class Terminal {
private Map<Integer, Integer> money= new HashMap<>();
private int balance;
private Scanner in;
private int AMOUNT_OF_5 = 500;
private int AMOUNT_OF_10 = 100;
private int AMOUNT_OF_15 = 60;
private int AMOUNT_OF_20 = 20;
private int AMOUNT_OF_50 = 4;
private int AMOUNT_OF_100 = 2;
public Terminal() {
money.put(5, AMOUNT_OF_5 * 5);
money.put(10, AMOUNT_OF_10 * 10);
money.put(15, AMOUNT_OF_15 * 15);
money.put(20, AMOUNT_OF_20 * 20);
money.put(50, AMOUNT_OF_50 * 50);
money.put(100, AMOUNT_OF_100 * 100);
balance = 5000;
in = new Scanner(System.in);
while (true) {
System.out.println("Банкомат");
System.out.println("1.Пополнить счёт");
System.out.println("2.Выдача наличных");
System.out.println("3.Остаток на счёте");
System.out.println("4.Выход");
System.out.print("Выберите нужную Вам операцию:");
int n = in.nextInt();
switch (n) {
case 1:
System.out.print("Внесите сумму для пополнения:");
int deposit = in.nextInt();
while ((deposit % 10) != 0){
System.out.println("Неверная сумма");
deposit = in.nextInt();
} if (balance >= deposit) {
balance = balance + deposit;
System.out.println("Ваш баланс был успешно пополнен");
}else {
System.out.println("Ваш депозит превышает лимит");
}
System.out.println("");
break;
case 2:
System.out.print("Введите сумму для снятия:");
int withdraw = in.nextInt();
while ((withdraw % 10) != 0){
System.out.println("Неверная сумма");
withdraw = in.nextInt();
}
if (balance >= withdraw) {
balance = balance - withdraw;
System.out.println("Введите сумму для снятия");
} else {
System.out.println("Недостаточный баланс");
}
System.out.println("");
break;
case 3:
checkAndGiveMoney();
System.out.println("Balance : " + balance);
System.out.println("");
break;
case 4:
System.exit(0);
}
}
}
public static void main (String[] args) throws java.lang.Exception
{
Terminal terminal = new Terminal();
terminal.checkAndGiveMoney();
}
public void checkAndGiveMoney(){
int requiredMoney = in.nextInt();
for (final Map.Entry<Integer, Integer> entry : money.entrySet()) {
int value = entry.getValue();
int key = entry.getKey();
if (value >= requiredMoney && ((value - requiredMoney) % key == 0)){
entry.setValue(value - requiredMoney);
balance = balance - requiredMoney;
System.out.println(entry.getKey() + ":" + requiredMoney / key);
break;
}
}
}
}
it is impossible to call a method right bottom checkAndGiveMoney implemented method that should display the number of the necessary bills such as 300 = 100: 3 tell me how I fit it in case 3? Balance to show up in the form of number of banknotes and their face value