import java.io.File;
import java.util.Scanner;

class BankAccountsApp {
	public static void main(String [] args) throws Exception {
		Scanner scanner = new Scanner(new File("bank_actions.text"));

		BankAccounts accounts = new BankAccounts();

		while (scanner.hasNextInt()) {
			int id = scanner.nextInt();
			String action = scanner.next();
			int amount;

			BankAccount account = accounts.search(id);
			if (account == null) {
				account = new BankAccount(id);
				accounts.add(account);
				System.out.println("Added " + account);
			}

			switch (action) {
				case "D":
					amount = scanner.nextInt();
					account.deposit(amount);
					System.out.println("After deposit of $" + amount + ": " + account);
					break;
				case "W":
					amount = scanner.nextInt();
					account.withdraw(amount);
					System.out.println("After withdrawal of $" + amount + ": " + account);
					System.out.println("Balance of account " + account.getId() + " after withdrawal of $" + amount + ": $" + account.getBalance());
					break;
				default:
					System.out.println("*** Error *** unknown action: " + action);
			}
		}

		System.out.println();
		System.out.println("=== Accounts ===");
		System.out.println(accounts);
	}	
}
