-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankAccount.java
More file actions
344 lines (280 loc) · 10.5 KB
/
Copy pathBankAccount.java
File metadata and controls
344 lines (280 loc) · 10.5 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
import java.util.Scanner;
public abstract class BankAccount{
/*
* This is the Bank account class used for generating accounts in the bank.
* @author Group 23
* @version 1.0
*/
private double balance = 0.0;
private String accountNumber = "0001";
private Customer accountHolder = new Customer();
/** This is the default constructor for the bank account.
**/
public BankAccount(){
accountNumber = getAccountNumber();
balance = getBalance();
accountHolder = null;
}
/** Constructor for bank account taking one argument.
@param startBalance is the balance to initialize the bank account with.
**/
public BankAccount(double startBalance){
accountNumber = getAccountNumber();
this.balance = startBalance;
accountHolder = null;
}
/** Constructor taking one argument.
@param <accountNumber> four digit string specifying the account number.
**/
public BankAccount(String accountNumber){
this.accountNumber = accountNumber;
balance = getBalance();
accountHolder = null;
}
/** Bank account constructor taking two arguments.
@param <startBalance>: the initial balance
@param <accountNumber>: 4 digit string specifying the account number.
**/
public BankAccount(double startBalance, String accountNumber){
this.accountNumber = accountNumber;
balance = startBalance;
accountHolder = null;
// if (accountNumber.length() != 4){
// this.accountHolder = null;
// }
// else{
// this.accountHolder = null;
// }
}
/**
Bank account constructor taking two arguments.
@param <accountHolder>: The customer for which to initialize the bank account for. Expects
Type Customer to have been initialized and passed to the this constructor. Will use the current
specified account holder.
@param <startBalance>: Initial balance for the customer.
@see Customer class
**/
public BankAccount(Customer accountHolder, double startBalance){
this.accountHolder = accountHolder;
balance = startBalance;
accountNumber = getAccountNumber();
}
/**
* Bank account constructor all necessary information about the customer and account.
* @param <accountHolder>: The customer for which to initialize the bank account for. Expects
Type Customer to have been initialized and passed to the this constructor. Will use the current
* specified account holder.
* <startBalance>: Initial balance for the customer.
* <accountNumber>: 4 digit string specifying the account number.
* @see Customer class
* @returns none
**/
public BankAccount(Customer accountHolder, double startBalance, String accountNumber){
this.accountNumber = accountNumber;
balance = startBalance;
this.accountHolder = accountHolder;
}
/**
* BankAccount copy constructor which will create an identical copy of a bank account.
* @param <copyAccount>: Bank account for which to copy information from.
* @see BankAccount class
* @returns none
**/
public BankAccount(BankAccount copyAccount){
accountNumber = copyAccount.getAccountNumber();
balance = copyAccount.getBalance();
accountHolder = copyAccount.getAccountHolder();
}
/** abstract method to get the monthly fees and interest. It is assumed that
classes inheriting bank account will implement their own
getMonthlyFeesAndInteres() dealio
@return <unknown>: some amount of type double
**/
protected abstract double getMonthlyFeesAndInterest();
/** This calls the get MonthlyFeesAndInterest() which will be defined by a
child class and adjusts the balance of the bank account accordingly
@see getMonthlyFeesAndInterest()
**/
public void monthEndUpdate(){
double amountAdjust = getMonthlyFeesAndInterest();
if (amountAdjust >= 0){
deposit(amountAdjust);
}
else {
balance = balance + amountAdjust;
}
}
/** This is a simple boolean to check if the amount in question is smaller
than the balance. This will be used to withdraw checking purposes
@param <anAmount>: the amount as type double to check against the balance
@return <hasSufficientFunds>: true if the withdraw would be allowed
**/
public boolean sufficientFunds(double anAmount){
boolean hasSufficientFunds;
if (anAmount <= getBalance()){
hasSufficientFunds = true;
}
else {
hasSufficientFunds = false;
}
return hasSufficientFunds;
}
/**
* Sets the current accountHolder to a default Customer class.
* @param none
* @see Customer class
* @returns accountHolder
**/
public Customer setAccountHolder(){
accountHolder = new Customer();
return accountHolder;
}
/**
* Sets the current accountHolder to a given Customer class. This enables other methods
* or constructors within BankAccount to grab the current account holder as accountHolder.
* @param none
* @see Customer class
* @returns accountHolder
**/
public Customer setAccountHolder(Customer currentCustomer){
accountHolder = currentCustomer;
return accountHolder;
}
/**
* Getter for the current reference to accountHolder.
* @param none
* @see Customer class
* @returns accountHolder
**/
public Customer getAccountHolder(){
return accountHolder;
}
/**
* Sets the current accountNumber to a specified string.
* @param <givenAccountNumber> an account number to set the reference to as a String.
* @see Customer class
* @returns accountNumber
**/
public void setAccountNumber(String givenAccountNumber){
accountNumber = givenAccountNumber;
}
/**
* Getter for the current accountNumber reference.
* @param none
* @see Customer class
* @returns accountNumber
**/
public String getAccountNumber(){
return accountNumber;
}
/**
* Sets the balance given an initial. This will yell at you if an initial balance less than
* zero is passed as a parameter.
* @param <givenBalance>: the initial balance to initialize <balance> to.
* @see Customer class
* @returns none
**/
public void setBalance(double givenBalance){
if (givenBalance>0){
balance = givenBalance;
}
else{
System.out.println("Invalid balance.");
}
}
/**
Getter for the current accountHolder's balance. Encapsulated.
@see Customer class
@return <copyBalance>: a copied amount of the customers balance
**/
public double getBalance(){
double copyBalance = balance;
return copyBalance;
}
/**
Getter for the name of the current account holder.
@see Customer class
@return <accountHolder> name of accountHolder
**/
public String getAccountName(){
accountHolder = getAccountHolder();
String copyName = accountHolder.getName();
return copyName;
}
/*
* Getter for the accountHolders customer identification.
* @param none
* @see Customer class
* @returns <accountholder>.customerID
*/
public int getID(){
accountHolder = getAccountHolder();
return accountHolder.getID();
}
/*
* toString method to replace the default.
* @param none
* @returns <acountInfo>: formatted information about the accountHholder and Account
*/
public String toString(){
String customerIDString = Integer.toString(getID());
String accountInfo1 = "("+getAccountName()+" "+customerIDString+") ";
String balanceString = Double.toString(getBalance());
String accountInfo2 = getAccountNumber()+": "+balanceString;
String accountInfo = accountInfo1 + accountInfo2;
return accountInfo;
}
/**
Boolean method to change the balance based on a withdraw amount. Also determines if the
withdraw is allowed or not.
@see hasSufficientFunds()
@param <withdrawAmount>: The amount to withdraw from the balance in the bank account.
@return <legalWithdraw>: boolean which returns if the widthraw is legal or not as true or false
**/
public void withdraw(double withdrawAmount){
if (withdrawAmount > 0){
if (sufficientFunds(withdrawAmount) == true){
balance = balance - withdrawAmount;
}
}
}
/**
Boolean method to modify the balance based on the depositAmount @see @params. Will not allow
negative deposit amounts.
@param <depositAmount>: The amount to deposit in the bank account balance. Will not accept
@return <legalDeposit>: a boolean if the transaction took place
a negative number.
**/
public boolean deposit(double depositAmount){
boolean legalDeposit;
if (depositAmount < 0){
//System.out.print("Cannot deposit negative amount.");
legalDeposit = false;
}
else{
balance = balance + depositAmount;
legalDeposit = true;
}
return legalDeposit;
}
/**
* Mutator method to modify the balance based on the transferAmount @see @params. Will not allow
* a negative balance of the current account. Transfers this amount to another bank account.
* @param <transferAmount>: the amount to transfer to the specified bank account.
* @return <legalTransfer>: a boolean to determine if the transfer is allowed.
**/
public void transfer(double transferAmount, BankAccount accountTo){
boolean legalDeposit = false;
boolean legalWithdraw;
// Deposit test
if (transferAmount > 0){
legalDeposit = true;
}
legalWithdraw = sufficientFunds(transferAmount);
if (legalWithdraw == true && legalDeposit == true){
withdraw(transferAmount);
accountTo.setBalance(accountTo.getBalance() + transferAmount);
}
}
// end of Class
}