File tree Expand file tree Collapse file tree 3 files changed +13
-7
lines changed
src/test/java/guru/springframework Expand file tree Collapse file tree 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) {
55 super (amount , currency );
66 }
77
8- public Money times (int multiplier ) {
9- return Money .dollar (this .amount * multiplier );
10- }
118}
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ public Franc(int amount, String currency) {
66 }
77
88 public Money times (int multiplier ) {
9- return Money . franc (this .amount * multiplier );
9+ return new Money (this .amount * multiplier , this . currency );
1010 }
1111
1212}
Original file line number Diff line number Diff line change 11package guru .springframework ;
22
3- public abstract class Money {
3+ public class Money {
44 protected int amount ;
55 protected String currency ;
66
@@ -14,7 +14,9 @@ protected String currency() {
1414 return currency ;
1515 }
1616
17- public abstract Money times (int multiplier );
17+ public Money times (int multiplier ) {
18+ return new Money (this .amount * multiplier , this .currency );
19+ }
1820
1921 public static Money dollar (int amount ) {
2022 return new Dollar (amount , "USD" );
@@ -27,8 +29,15 @@ public static Money franc(int amount) {
2729 public boolean equals (Object o ) {
2830 Money money = (Money ) o ;
2931 return amount == money .amount
30- && this .getClass () == money .getClass () ;
32+ && this .currency == money .currency ;
3133 }
3234
35+ @ Override
36+ public String toString () {
37+ return "Money{" +
38+ "amount=" + amount +
39+ ", currency='" + currency + '\'' +
40+ '}' ;
41+ }
3342
3443}
You can’t perform that action at this time.
0 commit comments