forked from Madonahs/Bank-Account-Draft
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.java
More file actions
executable file
·93 lines (70 loc) · 1.81 KB
/
Account.java
File metadata and controls
executable file
·93 lines (70 loc) · 1.81 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package Root;
import java.util.ArrayList;
/**
* @author syombua
*
*/
public class Account {
private String name;
/**
*
*/
private String uuid;
private User holder;
private ArrayList<Transaction> transaction;
public Account(String name, User holder, Bank theBank)
{
//set the account name and holder
this.name = name;
this.holder = holder;
//get account uuid
this.uuid = theBank.getNewAccontUUID();
//initialize transaction
this.transaction = new ArrayList<Transaction>();
}
//get the account ID
public String getUUID ()
{
return this.uuid;
}
public String getSummaryLine()
{
// TODO Auto-generated method stub
//get the accounts balance
double balance = this.getBalance();
//format the summary line depending on 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()
{
// TODO Auto-generated method stub
double balance = 0;
for(Transaction t: this.transaction)
{
balance += t.getAmount();
}
return balance;
}
public void printTransHistory()
{
System.out.printf("\nTranscation History for accounts %s\n", this.uuid);
for(int t= this.transaction.size()-1;t>=0;t--)
{
System.out.printf(this.transaction.get(t).getSummaryLine());
}
System.out.println(); // TODO Auto-generated method stub
}
public void addTransaction(double amount, String memo)
{
// TODO Auto-generated method stub
//create new transaction object
Transaction newTrans = new Transaction(amount,memo,this);
this.transaction.add(newTrans);
}
}