-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransaction.java
More file actions
33 lines (27 loc) · 999 Bytes
/
Transaction.java
File metadata and controls
33 lines (27 loc) · 999 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
31
32
33
package models;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Transaction {
private String type;
private double amount;
private String dateTime;
// Constructor 1: Used when creating a NEW transaction like (Deposit/Withdraw)
public Transaction(String type, double amount) {
this.type = type;
this.amount = amount;
this.dateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
}
// Constructor 2: Used when reading from FILE (Fixes your list.add error)
public Transaction(String line) {
// We just store the raw line for history display purposes in this demo
this.type = line;
this.amount = 0;
this.dateTime = "";
}
@Override
public String toString() {
// If it was loaded from a file, it's already a full string, just return it.
if (dateTime.equals("")) return type;
return "[" + dateTime + "] " + type + ": " + amount;
}
}