-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSavingsAccount.java
More file actions
104 lines (92 loc) · 2.55 KB
/
SavingsAccount.java
File metadata and controls
104 lines (92 loc) · 2.55 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
/**
* @author Shreeniket Bendre
* Project: BankAccount
* Class: SavingsAccount.java
* Parent: BankAccount.java
* Notes: Please ignore commented code. It is for the extra credit portion of the project.
*/
public class SavingsAccount extends BankAccount{
private double intRate;
private int numTransfers;
private final double MIN_BAL;
private final double MIN_BAL_FEE;
private final int MAX_TRANSFER = 6;
private final double TRANSACTION_FEE = 10;
public SavingsAccount(String n, double b, double r, double mb, double mbf) {
super(n,b);
intRate = r;
MIN_BAL = mb;
MIN_BAL_FEE = mbf;
}
public SavingsAccount(String n, double r, double mb, double mbf) {
super(n,0);
intRate = r;
MIN_BAL = mb;
MIN_BAL_FEE = mbf;
}
public void withdraw (double amt) {
boolean allow = true;
boolean mbf = false;
if (amt<0) allow = false;
if (getBalance()-amt<0) allow = false;
if (!allow) throw new IllegalArgumentException("Invalid Withdraw");
if (getBalance()-amt<MIN_BAL && allow)mbf=true;
if(allow) {
double amtDraw = amt;
if (mbf) amtDraw += MIN_BAL_FEE;
super.withdraw(amtDraw);
}
}
public void deposit (double amt) {
if(amt>=0) {
super.deposit(amt);
}
else {
throw new IllegalArgumentException();
}
}
public void transfer(BankAccount other, double amt) {
boolean allow = true;
boolean ca = false;
boolean tf = false;
boolean mbf = false;
if (amt<0) allow = false;
if (getBalance()-amt<0) allow = false;
if (!getName().equals(other.getName())) allow = false;
if (!allow) throw new IllegalArgumentException("Invalid Transfer");
else {
if (other instanceof CheckingAccount) ca = true;
if (numTransfers >= MAX_TRANSFER && ca) tf = true;
if (getBalance()-amt < MIN_BAL) mbf = true;
double amtTran = amt;
if (tf) amtTran+=TRANSACTION_FEE;
if (mbf) amtTran+=MIN_BAL_FEE;
super.transfer(other, amtTran);
numTransfers++;
}
}
public void addInterest() {
double interest = getBalance()+(getBalance()*intRate);
super.deposit(interest);
}
public void endOfMonthUpdate() {
double interest = getBalance()+(getBalance()*intRate);
super.deposit(interest);
numTransfers = 0;
}
// public void setNumTransfers(int num) {
// numTransfers = num;
// }
// public double getRate() {
// return intRate;
// }
// public double getMB() {
// return MIN_BAL;
// }
// public double getMBF() {
// return MIN_BAL_FEE;
// }
// public int getNumTransfers() {
// return numTransfers;
// }
}