-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransaction.java
More file actions
63 lines (47 loc) · 1.52 KB
/
Copy pathTransaction.java
File metadata and controls
63 lines (47 loc) · 1.52 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Abstract class Transacation: Implementation for the different transactions at the user/customer level
// Implements the BankComponent interface
import java.util.Date;
abstract public class Transaction implements BankComponent, Exchangeable {
// private data members for any Transaction
private final Account account;
private final BankUser user;
private final Date date;
private final ID id = new ID();
private Currency value;
// constructor for a transaction
public Transaction(Account account, BankUser user, Currency value, Date date) {
this.account = account;
this.user = user;
this.value = value;
this.date = date;
}
// getter methods for a transaction
public Account getAccount() {
return account;
}
public BankUser getUser() {
return user;
}
public Currency getValue() {
return value;
}
public Date getDate() {
return date;
}
public ID getID() {
return id;
}
// returns directly the value of the currency as a double (not the currency object itself)
public double getValueAsDouble() {
return value.getValue();
}
// toString() implementation for a Transaction
public String toString() {
String strRepr = "(" + this.getID() + ")" + ": " + value + " (" + date.toString() + ")";
return strRepr;
}
// exchanges to another Currency type
public void exchangeTo(String currency) {
value = value.convertTo(currency);
}
}