The Vault
Lena doesn't trust the counter: she wants her gold in the bank's vault, deep underground. In the array accounts, her account is now created with new VaultAccount("Lena", 75), and the last transaction today is her withdrawal.
A vault account works like any other, with two differences. Every withdrawal costs vaultFee gold extra, so it fails when the account can't pay both the amount and the fee. And in the list of accounts, a vault account has (vault) after its gold. Lena withdraws 60 gold, which costs her 62, so 13 are left:
Kira: 120 gold
Bruno: 40 gold
Lena: 75 gold (vault)
The bank holds 235 gold.
Bruno deposits 30 gold. Balance: 70
Kira withdraws 50 gold. Balance: 70
Bruno can't withdraw 100 gold: not enough gold
Mira can't deposit 10 gold: no account
Lena withdraws 60 gold. Balance: 13
Kira: 70 gold
Bruno: 70 gold
Lena: 13 gold (vault)
The bank holds 153 gold.A tip: a class that extends Account inherits everything from it, and it can override the methods that work differently and call the parent's version with super, as in the Classes lesson.
That's the whole project. Your bank keeps its gold in objects that guard their own rules, the result of every transaction says whether it worked and why not, and a new kind of account took just one short class. In the next lesson, Utility Types, you'll build new types out of the ones you have. And then, in the final project, you'll put the whole course together.
Instructions
Write the class VaultAccount, so that Lena's account is listed with (vault).
Make withdrawals from a vault account cost the fee.
Start programming for free
3/3