-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDriver
263 lines (240 loc) · 6.57 KB
/
Driver
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
package assignment2;
package assignment2;
import javax.swing.JOptionPane;
public class Driver {
public static void main(String[] args)
{
Customer ryan = new Customer(1, "Ryan", "1111 WallyWorld Ln");
Customer jon = new Customer(2, "Jon", "1111 NotWallyWorld Ln");
while(true)
{
String input = JOptionPane.showInputDialog("Input Transaction");
if(input == null)
{
continue;
}
String splitInput[] = input.split(" ");
int isTran;
try
{
isTran = isValid(splitInput);
}
catch(Exception e)
{
isTran = 0;
}
if(isTran == 0)
{
System.out.println("Error, try again BITCH");
}
else
{
Customer myCustomer;
if(splitInput[0].equals("1"))
{
myCustomer = ryan;
}
else
{
myCustomer = jon;
}
processTransaction(myCustomer, isTran, splitInput);
String promptUser = JOptionPane.showInputDialog("Wish to Continue?");
while(!promptUser.equals("Y") && !promptUser.equals("N"))
{
promptUser = JOptionPane.showInputDialog("Wish to Continue?");
}
if(promptUser.equals("N"))
{
summarize(ryan,jon);
return;
}
}
}
}
/**
*
* @param input
* @return will return 0 if invalid, 1 if valid, -1 if
*/
public static int isValid(String[] input)
{
if(input.length < 3 || input.length > 5)
{
return 0;
}
if(input[1].equals("I"))
{
if(input.length == 3 && (input[2].equals("S") || input[2].equals("L") || input[2].equals("A")))
{
return 1; //if we are computing interest return a 1
}
}
else if(input.length == 3 && input[1].equals("G") &&
(input[2].equals("S") || input[2].equals("L") ||
input[2].equals("A") || input[2].equals("C")))
{
return -2; //if we are getting a value return a -2
}
Double amount;
try
{
amount = Double.valueOf(input[2]);
}
catch(Exception e)
{
amount = 0.0;
return 0;
}
if(input[0].charAt(0) != '1' && input[0].charAt(0) != '2')
{
return 0; //if input is invalid return a 0
}
else if(input[1].charAt(0) != 'D' && input[1].charAt(0) != 'W' && input[1].charAt(0) !=
'I' && input[1].charAt(0) != 'T' && input[1].charAt(0) != 'G')
{
return 0;
}
else if(input[1].equals("T"))
{
if(amount > 0 && input.length == 5)
{
if(input[3].equals("S") || input[3].equals("L")
|| input[3].equals("A") || input[3].equals("C"))
{
if(input[4].equals("S") || input[4].equals("L")
|| input[4].equals("A") || input[4].equals("C"))
{
return -1; //if we are doing a transaction return a -1
}
}
}
}
else if(input[1].equals("W") || input[1].equals("D"))
{
if(amount > 0 && input.length == 4 &&
(input[3].equals("S") || input[3].equals("L")
|| input[3].equals("A") || input[3].equals("C")))
{
return 2;//if we are doing a deposit or withdrawal return 2
}
}
return 0;
}
public static void processTransaction(Customer myCust, int whatTran, String[] input)
{
if(whatTran == -2)
{
switch(input[2].charAt(0))
{
case 'S': System.out.println("Customer " + myCust.custNumber +
" savings balance is " + myCust.savAcct.getBalance());
return;
case 'L': System.out.println("Customer " + myCust.custNumber +
" loan account balance is " + myCust.loanAcct.getBalance());
return;
case 'A': System.out.println("Customer " + myCust.custNumber +
" auto loan account balance is " + myCust.autoLoanAcct.getBalance());
return;
case 'C': System.out.println("Customer " + myCust.custNumber +
" checkings balance is " + myCust.checkAcct.getBalance());
return;
}
}
else if(whatTran == 1)
{
switch(input[2].charAt(0))
{
case 'S': myCust.savAcct.applyInterest();
return;
case 'L': myCust.loanAcct.applyInterest();
return;
case 'A': myCust.autoLoanAcct.applyInterest();
return;
}
}
Double amount = Double.valueOf(input[2]);
if(whatTran == 2)
{
if(input[1].equals("D"))
{
switch(input[3].charAt(0))
{
case 'S': myCust.savAcct.deposit(amount);
break;
case 'L': myCust.loanAcct.deposit(amount);
break;
case 'A': myCust.autoLoanAcct.deposit(amount);
break;
case 'C': myCust.checkAcct.deposit(amount);
break;
}
}
if(input[1].equals("W"))
switch(input[3].charAt(0))
{
case 'S': myCust.savAcct.withdraw(amount);
break;
case 'L': myCust.loanAcct.withdraw(amount);
break;
case 'A': myCust.autoLoanAcct.withdraw(amount);
break;
case 'C': myCust.checkAcct.withdraw(amount);
break;
}
}
else if(whatTran == -1)
{
processTransfer(myCust,whatTran,input);
}
}
public static void processTransfer(Customer myCust, int whatTran, String[] input)
{
Double amount = Double.valueOf(input[2]);
BankAccount myWitAccount;
BankAccount myDepAccount;
switch(input[3].charAt(0))
{
case 'S': myWitAccount = myCust.savAcct;
break;
case 'L': myWitAccount = myCust.loanAcct;
break;
case 'A': myWitAccount = myCust.autoLoanAcct;
break;
case 'C': myWitAccount = myCust.checkAcct;
break;
default: myWitAccount = myCust.checkAcct;
}
switch(input[4].charAt(0))
{
case 'S': myDepAccount = myCust.savAcct;
break;
case 'L': myDepAccount = myCust.loanAcct;
break;
case 'A': myDepAccount = myCust.autoLoanAcct;
break;
case 'C': myDepAccount = myCust.checkAcct;
break;
default: myDepAccount = myCust.checkAcct;
}
myWitAccount.withdraw(amount);
myDepAccount.deposit(amount);
}
public static void summarize(Customer cust1, Customer cust2)
{ //summarize both Customer's data
System.out.println("Customer " + cust1.custName + "'s summary:");
System.out.println("ID #: " + cust1.custNumber);
System.out.println("Address: " + cust1.custAddress);
System.out.println("Checking account balance: " + cust1.checkAcct.balance);
System.out.println("Savings account balance: " + cust1.savAcct.balance);
System.out.println("Loan account balance: " + cust1.loanAcct.balance);
System.out.println("Auto loan account balance: " + cust1.autoLoanAcct.balance + "\n");
System.out.println("Customer " + cust2.custName + "'s summary:");
System.out.println("ID #: " + cust2.custNumber);
System.out.println("Address: " + cust2.custAddress);
System.out.println("Checking account balance: " + cust2.checkAcct.balance);
System.out.println("Savings account balance: " + cust2.savAcct.balance);
System.out.println("Loan account balance: " + cust2.loanAcct.balance);
System.out.println("Auto loan account balance: " + cust2.autoLoanAcct.balance);
}
}