Skip to content

Commit bd7fe65

Browse files
springframeworkguru#26 - TDD Chapter 10 - Interesting Times - times() Method was refactored and consolidated in the Money Class
1 parent 654d6eb commit bd7fe65

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

src/main/java/guru/springframework/Dollar.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff 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
}

src/main/java/guru/springframework/Franc.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff 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
}

src/main/java/guru/springframework/Money.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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
}

0 commit comments

Comments
 (0)