... account1.deposit(depositAmount); // add to account1's balance
24
25        // display balances
26        System.out.printf("%s balance: $%.2f %n",
27           account1.getName(), account1.getBalance() );
28        System.out.printf("%s balance: $%.2f %n%n",
29           account2.getName(), account2.getBalance() );
30
31        System.out.print("Enter deposit amount for account2: "); // prompt
32        depositAmount = input.nextDouble(); // obtain user input
33        System.out.printf("%nadding %.2f  to account2 balance%n%n",
34            depositAmount);
35         account2.deposit(depositAmount); // add to account2 balance
36
37        // display balances
38        System.out.printf("%s balance: $%.2f %n",
39           account1.getName(), account1.getBalance() );
40        System.out.printf("%s balance: $%.2f %n%n",
41           account2.getName(), account2.getBalance() );
42 } ...

Get Java How To Program, Late Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.