So far we’ve been working with composing shape objects with GUI Java classes. Now we’re going to practice composing objects that only output to the console.
Rx: <20 min Av: 20-40 min Sd: 40-60 min DNF: 60+ min
BankAccount_uLogin
BankAccount
class with:
deposit
and a debit
method. The method signatures are similar in that they have no return value and one parameter.print
method that prints out the account information, including the current balance. Make sure to use proper formatting so both dollars and cents are displayed correctly. This method should take no parameters and return nothing. (Hint: check out Java’s NumberFormat.getCurrencyInstance() and this usage example.) main
method that creates a new, empty BankAccount
stored in a local variable, myBankAccount
.
BankAccount
& print the balance.BankAccount
& print the balance.debit
& deposit
methods so that negative amounts have no effect. For example, myBankAccount.deposit(5) will add $5, but myBankAccount.deposit(-5) will do nothing. debit
method to make sure there are sufficient funds before deducting from the balance. Print an error message if there are insufficient funds.Bank
class that can store multiple BankAccount
objects:
add
method that takes an account as a parameter and adds it to the list of accounts.print
method that prints out the Bank’s name followed by an overview of all the accounts (i.e., by calling print
on each account). main
method that creates a new Bank
. Add 2-3 accounts to this bank and make sure they have balances > 0. Display the Bank information by calling print
.Once you’ve finished doing the WOD a single time, watch me do it:
You’ll learn significantly less from watching me solve the practice HW if you haven’t attempted the HW yourself first.
While it’s an achievement to finish the HW no matter how long it takes, you might experience “diminishing returns” if you work longer than the DNF time. Thus, it might be strategic to stop working at the DNF time and watch my solution.
After watching my solution, I recommend that you repeat the HW if you have not achieved at least Av performance. If so, be sure to:
Feel free to keep trying until you make Rx if that’s of interest to you.