Pleas help me!
I have a problem with my ArrayList, I don't understand how the user input should be stored in the ArrayList and how I can print the ArrayList
my code:
import java.util.Scanner; import java.util.ArrayList; class Bank{ double balance; //Account account; ArrayList<Account>account; CommandReader commandReader; boolean name; Bank(){ commandReader = new CommandReader(); } void run(){ commandReader.run(); } void enroll(String name){ if(account.contains(name)){ System.out.println("already enrolled"); } else { account.add(new Account()); account = new ArrayList<Account>(); } } void deposit(String name, int amount){ if (account.contains(name)){ balance = balance + amount; } else { System.out.println("no such name "+name); } } void withdraw(String name, int amount){ if(account.contains(name)){ balance = balance - amount; } else { System.out.println("no such name "+name); } } void print(String name){ System.out.println("Account of "+name); System.out.println(" balance: "+balance); } void printAll(){ System.out.println(account); } void printRed(){ if (balance < 0){ System.out.println(account); } else { System.out.print("no negative balances"); } } void interest (double rate){ } public static void main(String[] args){ new Bank().run(); } } class CommandReader{ Bank bank; Account account; /* CommandReader(Bank bank) { this.bank = bank; Why should this be here? }*/ //CommandReader() { // bank = new Bank(); //} // @pre: input complies to specified format void run(){ Scanner scanner; String command; String name; int amount; scanner = new Scanner(System.in); bank = new Bank(); do{ command = scanner.next().toLowerCase(); if (command.equals("enroll")) { name = scanner.next(); bank.enroll(name); } else if (command.equals("deposit")) { name = scanner.next(); amount = scanner.nextInt(); bank.deposit(name, amount); } else if (command.equals("withdraw")) { name = scanner.next(); amount = scanner.nextInt(); bank.withdraw(name, amount); } else if (command.equals("print")) { name = scanner.next(); bank.print(name); } else if (command.equals("printall")) { bank.printAll(); } else if (command.equals("printred")) { bank.printRed(); } else if (command.equals("interest")) { double rate = scanner.nextDouble(); bank.interest(rate); } else if (command.equals("stop")) { // do nothing } else { System.out.println("unknown command"); // skip rest of line scanner.nextLine(); } } while (! command.equals("stop")); } } class Account{ double balance; String name; Account(){ balance = 0; this.name = name; } String getName(){ return this.name; } void setName(String name){ this.name = name; } }