publicclass accounts {
// Create ten accountsprivate Account[] accounts = new Account[10];
publicaccounts() {
for (int i = 0; i < accounts.length; i++) {
accounts[i] = new Account();
accounts[i].setId(i);
accounts[i].setBalance(100);
}
continueATM:while (true) {
System.out.print("Enter an id: ");
id = input.nextInt();
if (id < 1 || id > 10) {
System.out.println("Please enter a correct id");
}
while (true) {
int choice = getAChoice();
switch (choice) {
case1:
System.out.println("The balance is " +
accounts[id].getBalance());
break;
case2:
withdraw();
break;
case3:
deposit();
break;
case4:
// You can rewrite the code without using the continue. // To do so, introduce a boolean variable to control one // customer sessioncontinue continueATM;
}
}
}
}
privatestatic java.util.Scanner input = new java.util.Scanner(
System.in);
int id;
publicstaticvoidmain(String[] args) {
new accounts();
}
publicvoidwithdraw() {
System.out.print("Enter an amount to withdraw: ");
int amount = input.nextInt();
if (amount <= accounts[id].getBalance()) {
accounts[id].withdraw(amount);
}
else {
System.out.print("The amount is too large, ignored");
}
}
publicvoiddeposit() {
System.out.print("Enter an amount to deposit: ");
int amount = input.nextInt();
if (amount >= 0) {
accounts[id].deposit(amount);
}
else {
System.out.print("The amount is negative, ignored");
}
}
publicintgetAChoice() {
int choice;
while (true) {
System.out.println("\nMain menu");
System.out.println("1: check balance");
System.out.println("2: withdraw");
System.out.println("3: deposit");
System.out.println("4: exit");
System.out.print("Enter a choice: ");
choice = input.nextInt();
if (choice < 1 || choice > 4) {
System.out.println("Wrond choice, try again: ");
}
else {
break;
}
}
return choice;
}
}