-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathMoney.java
More file actions
30 lines (23 loc) · 724 Bytes
/
Money.java
File metadata and controls
30 lines (23 loc) · 724 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package guru.springframework;
public abstract class Money {
private final String currency;
protected final int amount;
public Money(int amount, String currency) {
this.amount = amount;
this.currency = currency;
}
protected String currency() {
return currency;
}
public abstract Money times(int multiplier);
public static Money dollar(int amount) {
return new Dollar(amount, "USD");
}
public static Money franc(int amount) {
return new Franc(amount, "CHF");
}
public boolean equals(Object object) {
Money money = (Money) object;
return amount == money.amount && this.getClass().equals(object.getClass());
}
}