-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransaction.java
More file actions
53 lines (45 loc) · 1.15 KB
/
Transaction.java
File metadata and controls
53 lines (45 loc) · 1.15 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
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Transaction class - represents a bank transaction.
*/
public class Transaction {
private String type;
private double amount;
private Date date;
private String description;
/**
* Constructor
*/
public Transaction(String type, double amount, Date date, String description) {
this.type = type;
this.amount = amount;
this.date = date;
this.description = description;
}
// Getters
public String getType() {
return type;
}
public double getAmount() {
return amount;
}
public Date getDate() {
return date;
}
public String getDescription() {
return description;
}
/**
* Formats the transaction details for display.
*/
public String getFormattedDetails() {
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
return String.format("%s: $%.2f - %s (%s)",
type, amount, description, dateFormat.format(date));
}
@Override
public String toString() {
return getFormattedDetails();
}
}