forked from ssoad/BankingSystem
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBank
More file actions
153 lines (129 loc) · 3.02 KB
/
Copy pathBank
File metadata and controls
153 lines (129 loc) · 3.02 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package Bank;
import java.io.Serializable;
import javax.swing.DefaultListModel;
import Exceptions.AccNotFound;
import Exceptions.InvalidAmount;
import Exceptions.MaxBalance;
import Exceptions.MaxWithdraw;
public class Bank implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private BankAccount[] accounts= new BankAccount[100];
public int addAccount(BankAccount acc)
{
int i=0;
for(i=0;i<100;i++)
{
if(getAccounts()[i]==null)
{
break;
}
}
getAccounts()[i]=acc;
return i;
}
public int addAccount(String name, double balance, double maxWithLimit ) throws Exception
{
SavingsAccount acc=new SavingsAccount(name, balance, maxWithLimit);
return this.addAccount(acc);
}
public int addAccount(String name, double balance, String tradeLicense) throws Exception
{
CurrentAccount acc = new CurrentAccount(name, balance,tradeLicense);
return this.addAccount(acc);
}
public int addAccount(String name, String institutionName, double balance, double min_balance) throws Exception
{
StudentAccount acc= new StudentAccount(name,balance,institutionName);
return this.addAccount(acc);
}
public BankAccount findAccount(String aacountNum)
{
int i;
for(i=0;i<100;i++)
{
if(getAccounts()[i]==null)
{
break;
}
if(getAccounts()[i].acc_num.equals(aacountNum))
{
return getAccounts()[i];
}
}
return null;
}
public void deposit(String aacountNum, double amt) throws InvalidAmount,AccNotFound
{
if(amt<0)
{
throw new InvalidAmount("Invalid Deposit amount");
}
BankAccount temp=findAccount(aacountNum);
if(temp==null)
{
throw new AccNotFound("Account Not Found");
}
if(temp!=null)
{
temp.deposit(amt);
}
}
public void withdraw(String aacountNum, double amt) throws MaxBalance,AccNotFound, MaxWithdraw, InvalidAmount
{
BankAccount temp=findAccount(aacountNum);
if(temp==null)
{
throw new AccNotFound("Account Not Found");
}
if(amt<=0)
{
throw new InvalidAmount("Invalid Amount");
}
if(amt>temp.getbalance())
{
throw new MaxBalance("Insufficient Balance");
}
if(temp!=null)
{
temp.withdraw(amt);
}
}
public DefaultListModel<String> display()
{
DefaultListModel<String> list=new DefaultListModel<String>();
int i;
// String type=null;
for(i=0;i<100;i++)
{
if(getAccounts()[i]==null)
{
break;
}
// if(getAccounts()[i].getClass().toString().equals("class Bank.SavingsAccount"))
// {
// type="Type: Savings Account";
// }
//
// else if(getAccounts()[i].getClass().toString().equals("class Bank.CurrentAccount"))
// {
// type="Type: Current Account";
// }
//
// else if(getAccounts()[i].getClass().toString().equals("class Bank.StudentAccount"))
// {
// type="Type: Student Account";
// }
list.addElement(getAccounts()[i].toString());
}
return list;
}
public BankAccount[] getAccounts() {
return accounts;
}
public void setAccounts(BankAccount[] accounts) {
this.accounts = accounts;
}
}