File tree Expand file tree Collapse file tree 3 files changed +20
-20
lines changed
src/main/java/guru/springframework Expand file tree Collapse file tree 3 files changed +20
-20
lines changed Original file line number Diff line number Diff line change @@ -8,9 +8,4 @@ public class Dollar extends Money {
88 public Dollar (int amount , String currency ) {
99 super (amount , currency );
1010 }
11-
12- @ Override
13- public Money times (int multiplier ) {
14- return Money .dollar (amount * multiplier );
15- }
1611}
Original file line number Diff line number Diff line change @@ -8,9 +8,4 @@ public class Franc extends Money {
88 public Franc (int amount , String currency ) {
99 super (amount , currency );
1010 }
11-
12- @ Override
13- public Money times (int multiplier ) {
14- return Money .franc (amount * multiplier );
15- }
1611}
Original file line number Diff line number Diff line change 33/**
44 * @author Patrick Corbett
55 */
6- public abstract class Money {
6+ public class Money {
77
88 protected int amount ;
99 protected String currency ;
@@ -22,14 +22,6 @@ protected String currency() {
2222 return currency ;
2323 }
2424
25- /**
26- * Abstract Times for money by a multiplier.
27- *
28- * @param multiplier the multiplier
29- * @return the money
30- */
31- public abstract Money times (int multiplier );
32-
3325 public static Money dollar (int amount ) {
3426 return new Dollar (amount , "USD" );
3527 }
@@ -41,6 +33,24 @@ public static Money franc(int amount) {
4133 public boolean equals (Object object ) {
4234 // Manual equals, left like this as equals with null will be done later
4335 Money money = (Money ) object ;
44- return amount == money .amount && this .getClass ().equals (object .getClass ());
36+ return amount == money .amount && this .currency .equals (money .currency );
37+ }
38+
39+ @ Override
40+ public String toString () {
41+ return "Money{" +
42+ "amount=" + amount +
43+ ", currency='" + currency + '\'' +
44+ '}' ;
45+ }
46+
47+ /**
48+ * Times for money by a multiplier.
49+ *
50+ * @param multiplier the multiplier
51+ * @return the money
52+ */
53+ public Money times (int multiplier ) {
54+ return new Money (amount * multiplier , this .currency );
4555 }
4656}
You can’t perform that action at this time.
0 commit comments