-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.java
More file actions
73 lines (53 loc) · 1.45 KB
/
Copy pathAccount.java
File metadata and controls
73 lines (53 loc) · 1.45 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
import java.util.*;
public class Account
{
private String name;
private String uuid;
private User holder;
private ArrayList<Transaction> transactions;
public Account(String name,User holder,Bank theBank)
{
this.name=name;
this.holder=holder;
this.uuid=theBank.getNewAccountUUID();
this.transactions=new ArrayList<Transaction>();
//add to holder and bank lists
}
public String getUUID()
{
return this.uuid;
}
public String getSummaryLine()
{
//get the accounts balance
double balance=this.getBalance();
//format the summaryline depending whether the balance is negative
if(balance >=0)
{
return String.format("%s : $%.02f : %s", this.uuid,balance,this.name);
}else{
return String.format("%s : $(%.02f) : %s",this.uuid,balance,this.name);
}
}
public double getBalance(){
double balance =0;
for(Transaction t: this.transactions){
balance +=t.getAmount();
}
return balance;
}
public void printTransHistory(){
System.out.printf("\nTransaction history for account %s\n",this.uuid);
for(int t=this.transactions.size()-1;t>=0;t--)
{
System.out.println(this.transactions.get(t).getSummaryLine());
}
System.out.println();
}
public void addTransaction(double amount, String memo)
{
//create new transaction object and add it to our list
Transaction newTrans=new Transaction(amount,memo,this);
this.transactions.add(newTrans);
}
}