File tree 3 files changed +13
-7
lines changed
src/test/java/guru/springframework 3 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,4 @@ public Dollar(int amount, String currency) {
5
5
super (amount , currency );
6
6
}
7
7
8
- public Money times (int multiplier ) {
9
- return Money .dollar (this .amount * multiplier );
10
- }
11
8
}
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ public Franc(int amount, String currency) {
6
6
}
7
7
8
8
public Money times (int multiplier ) {
9
- return Money . franc (this .amount * multiplier );
9
+ return new Money (this .amount * multiplier , this . currency );
10
10
}
11
11
12
12
}
Original file line number Diff line number Diff line change 1
1
package guru .springframework ;
2
2
3
- public abstract class Money {
3
+ public class Money {
4
4
protected int amount ;
5
5
protected String currency ;
6
6
@@ -14,7 +14,9 @@ protected String currency() {
14
14
return currency ;
15
15
}
16
16
17
- public abstract Money times (int multiplier );
17
+ public Money times (int multiplier ) {
18
+ return new Money (this .amount * multiplier , this .currency );
19
+ }
18
20
19
21
public static Money dollar (int amount ) {
20
22
return new Dollar (amount , "USD" );
@@ -27,8 +29,15 @@ public static Money franc(int amount) {
27
29
public boolean equals (Object o ) {
28
30
Money money = (Money ) o ;
29
31
return amount == money .amount
30
- && this .getClass () == money .getClass () ;
32
+ && this .currency == money .currency ;
31
33
}
32
34
35
+ @ Override
36
+ public String toString () {
37
+ return "Money{" +
38
+ "amount=" + amount +
39
+ ", currency='" + currency + '\'' +
40
+ '}' ;
41
+ }
33
42
34
43
}
You can’t perform that action at this time.
0 commit comments