-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTransaction.java
65 lines (56 loc) · 2.39 KB
/
Transaction.java
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
package ATMBankManager;
import java.util.Date;
public class Transaction {
private double amount;
private Date timestamp;
private String memo; // A note attached to a transaction, explaining nature of transaction.
private Account inAccount; // Account transaction was performed.
// Overloading contructors: Two constructors for a new Transaction. The correct one is deduced by the arguments passed with a call, done by Java/JVM.
/**
*
* @param amount
* @param inAccount
*/
// Transaction constructor in case of a transaction with No optional Memo attached to it. Set all properties, and Memo to "".
// Create a new Transaction. @param amount (amount involved in transaction), @param inAccount (the account the transaction belongs to).
public Transaction(double amount, Account inAccount) {
this.amount = amount;
this.inAccount = inAccount;
this.timestamp = new Date(); // Current date.
this.memo = ""; // There is no memo, so set to empty string.
}
/**
*
* @param amount
* @param memo
* @param inAccount
*/
// Transaction constructor in case of a transaction WITH an optional memo attached. Set the attached Memo.
// Create a new Transaction. @param amount (amount involved in transaction), @param memo (memo for the transaction), @param inAccount (the account the transaction belongs to).
public Transaction(double amount, String memo, Account inAccount) {
// Call the other constructor first. (The two argument Contructor, where NO Memo is in argument or with the Transaction).
this(amount, inAccount);
// With all the properties now set (by calling prev. constructor), but without the Memo (set as ""), we can set the Memo here, (from "", to the argument value), in this Constructor.
this.memo = memo;
}
/**
*
* @return
*/
// Get the amount of a transaction.
public double getAmount() {
return this.amount;
}
/**
*
* @return
*/
// Get a string with the summary of a Transaction.
public String getSummaryLine() {
if(this.amount >= 0) {
return String.format("%s : £%.02f : %s", this.timestamp.toString(), this.amount, this.memo);
} else {
return String.format("%s : £%.02f : %s", this.timestamp.toString(), -this.amount, this.memo);
}
}
}