|
1 | 1 | package com.codedifferently.lesson17.bank.exceptions;
|
2 | 2 |
|
3 | 3 | import com.codedifferently.lesson17.bank.Check;
|
4 |
| -import com.codedifferently.lesson17.bank.CheckingAccount; |
5 | 4 |
|
6 | 5 | public class MoneyOrder extends Check {
|
7 | 6 |
|
8 |
| - public MoneyOrder(String checkNumber, double amount, CheckingAccount account) { |
| 7 | + public MoneyOrder( |
| 8 | + String checkNumber, |
| 9 | + double amount, |
| 10 | + com.codedifferently.lesson17.bank.CheckingAccount account) { |
9 | 11 | super(checkNumber, amount, account);
|
10 | 12 | if (amount < 0) {
|
11 | 13 | throw new IllegalArgumentException("MoneyOrder amount must be positive");
|
12 | 14 | }
|
13 | 15 | account.withdraw(amount);
|
14 | 16 | }
|
15 | 17 |
|
16 |
| - @Override |
17 | 18 | /**
|
18 | 19 | * Deposits the check into an account.
|
19 | 20 | *
|
20 | 21 | * @param toAccount The account to deposit the check into.
|
21 | 22 | */
|
22 | 23 | public void depositFunds(CheckingAccount toAccount) {
|
23 | 24 | if (getIsVoided()) {
|
24 |
| - throw new CheckVoidedException("MoneyOrder is voided"); |
| 25 | + throw new UnsupportedOperationException("MoneyOrder is voided"); |
25 | 26 | }
|
26 | 27 | toAccount.withdraw(getAmount());
|
27 | 28 | ((CheckingAccount) getAccount()).withdraw(getAmount());
|
28 |
| - toAccount.deposit(getAmount()); |
| 29 | + ((CheckingAccount) toAccount).deposit(getAmount()); |
29 | 30 | voidCheck();
|
30 | 31 | }
|
31 | 32 |
|
| 33 | + public class CheckingAccount { |
| 34 | + private String accountNumber; |
| 35 | + |
| 36 | + public CheckingAccount(String accountNumber) { |
| 37 | + this.accountNumber = accountNumber; |
| 38 | + } |
| 39 | + |
| 40 | + public void withdraw(double amount) { |
| 41 | + // TODO Auto-generated method stub |
| 42 | + throw new UnsupportedOperationException("Unimplemented method 'withdraw'"); |
| 43 | + } |
| 44 | + |
| 45 | + public void deposit(double amount) { |
| 46 | + // TODO Auto-generated method stub |
| 47 | + throw new UnsupportedOperationException("Unimplemented method 'deposit'"); |
| 48 | + } |
| 49 | + |
| 50 | + public String getAccountNumber() { |
| 51 | + return this.accountNumber; |
| 52 | + } |
| 53 | + } |
| 54 | + |
32 | 55 | @Override
|
33 | 56 | public String toString() {
|
34 | 57 | return "MoneyOrder{"
|
|
0 commit comments