-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTransaction.java
More file actions
31 lines (29 loc) · 1.05 KB
/
Transaction.java
File metadata and controls
31 lines (29 loc) · 1.05 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
import java.util.*;
public class Transaction{
private double amount;//amount of this trasaction
private Date timestamp;//time and date of this transcation
private String memo;//memo for this transaction
private Account inAccount;//the account in which transaction is performed
public Transaction(double amount,Account inAccount){
this.amount = amount;
this.inAccount = inAccount;
this.timestamp = new Date();
this.memo = "";
}
public Transaction(double amount,String memo,Account inAccount){
//call two args constructor first
this(amount,inAccount);
//set the memo
this.memo = memo;
}
public double getAmount(){
return this.amount;
}
public String getSummaryLine(){
if(this.amount >= 0){
return String.format(this.timestamp.toString()+" : $"+this.amount+" : "+this.memo);
}else{
return String.format(this.timestamp.toString()+" : $("+this.amount+") : "+this.memo);
}
}
}