-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckingAccount.java
More file actions
130 lines (120 loc) · 2.91 KB
/
CheckingAccount.java
File metadata and controls
130 lines (120 loc) · 2.91 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
/**
* @author Shreeniket Bendre
* Project: BankAccount
* Class: CheckingAccount.java
* Parent: BankAccount.java
* Notes: Please ignore commented code. It is for the extra credit portion of the project.
*/
public class CheckingAccount extends BankAccount {
private final double OVER_DRAFT_FEE;
private final double TRANSACTION_FEE;
private final int FREE_TRANS;
private int numTransactions;
public CheckingAccount(String n, double b, double odf, double tf, int freeTrans) {
super(n, b);
OVER_DRAFT_FEE = odf;
TRANSACTION_FEE = tf;
FREE_TRANS = freeTrans;
numTransactions = 0;
}
public CheckingAccount(String n, double odf, double tf, int freeTrans) {
super(n, 0);
OVER_DRAFT_FEE = odf;
TRANSACTION_FEE = tf;
FREE_TRANS = freeTrans;
}
public void deposit (double amt) {
boolean allow = true;
if (numTransactions>=FREE_TRANS) {
if (getBalance()-amt-TRANSACTION_FEE<0) {
allow = false;
}
}
else {
if (getBalance()+amt<=0) allow = false;
}
if (amt<0) {
allow = false;
}
if (!allow) {
throw new IllegalArgumentException("Not Valid Deposit");
}
if (allow) {
boolean tf = true;
if (numTransactions<FREE_TRANS) {
tf = false;
}
double amtDep = amt;
if (tf) amtDep-=TRANSACTION_FEE;
super.deposit(amtDep);
numTransactions++;
}
}
public void withdraw(double amt) {
boolean allow = true;
if (amt<0 || getBalance()<0) {
allow = false;
throw new IllegalArgumentException("Not Valid Withdrawl");
}
if (allow) {
double amtDep;
boolean odf = true;
boolean tf = true;
if (numTransactions<FREE_TRANS) {
tf = false;
}
if (getBalance()-amt>=0 && !tf) {
odf = false;
}
if (getBalance()-amt-TRANSACTION_FEE>=0 && tf) {
odf = false;
}
numTransactions++;
amtDep = amt;
if (odf) amtDep+=OVER_DRAFT_FEE;
if (tf) amtDep+=TRANSACTION_FEE;
super.withdraw(amtDep);
}
}
public void transfer(BankAccount other, double amt) {
boolean allow = true;
boolean tf = true;
if (!getName().equals(other.getName())) allow = false;
if (amt<0) allow = false;
if (numTransactions<FREE_TRANS) {
tf = false;
}
if (getBalance()-amt<0) {
allow = false;
}
if (!allow) {
throw new IllegalArgumentException("Not Valid Withdrawl");
}
if (allow) {
double amtTrans = amt;
if (tf) {
amtTrans-=TRANSACTION_FEE;
}
super.transfer(other, amtTrans);
numTransactions++;
}
}
public void endOfMonthUpdate() {
numTransactions = 0;
}
// public void setNumTransactions(int num) {
// numTransactions = num;
// }
// public double getODF() {
// return OVER_DRAFT_FEE;
// }
// public double getTF() {
// return TRANSACTION_FEE;
// }
// public int getFreeTrans() {
// return FREE_TRANS;
// }
// public int getNumTransactions() {
// return numTransactions;
// }
}