-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransaction.java
More file actions
80 lines (65 loc) · 1.62 KB
/
Transaction.java
File metadata and controls
80 lines (65 loc) · 1.62 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Transaction {
// The amount of this transaction
private double amount;
private String date;
private DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
// A memo for this transaction
private String memo;
// The account in which the transaction was performed
private Account inAccount;
/**
* Create a new transaction
*
* @param amount
* The amount transacted
* @param inAccount
* The account the transaction belongs to
*/
public Transaction(double amount, Account inAccount) {
this.amount = amount;
this.inAccount = inAccount;
this.date = (formatter.format(new Date()));
this.memo = "";
}
/**
* Creates a new transaction
*
* @param amount
* The amount transacted
* @param inAccount
* The account the transaction belongs to
* @param memo
* The memo for the transaction
*/
public Transaction(double amount, Account inAccount, String memo) {
// Call the two-arg constructor first
this(amount, inAccount);
// Set the memo
this.memo = memo;
}
/**
* Get the amount of the transaction
*
* @return The amount
*/
public double getAmount() {
return this.amount;
}
/**
* Get a string summarizing the transaction
*
* @return The string summary string
*/
public String getSummaryLine() {
if (this.amount >= 0) {
return String.format("%s : $%.02f : %s", this.date, this.amount,
this.memo);
} else {
return String.format("%s : $(%.02f): %s", this.date, -this.amount,
this.memo);
}
}
}