forked from Ryanjmeek/BankAccounts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDriver
132 lines (114 loc) · 2.43 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
package assignment2;
import javax.swing.JOptionPane;
import java.lang;
public class Driver {
public static void main()
{
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");
String splitInput[] = input.split(" ");
int isTran = isValid(splitInput);
if(isTran == 0)
{
System.out.println("Error, try again");
}
else
{
Customer myCustomer;
if(splitInput[0] == "1")
{
myCustomer = ryan;
}
else
{
myCustomer = jon;
}
processTransaction(myCustomer, isTran, splitInput);
String promptUser = JOptionPane.showInputDialog("Wish to Continue?");
while(promptUser != "Y" && promptUser != "N")
{
promptUser = JOptionPane.showInputDialog("Wish to Continue?");
}
if(promptUser == "N")
{
summarize(ryan,jon);
return;
}
}
}
}
/**
*
* @param input
* @return will return 0 if invalid, 1 if valid, -1 if
*/
public static int isValid(String[] input)
{
Double amount = Double.valueOf(input[2]);
if(input[0] != "1" && input[0]!= "2")
{
return 0;
}
else if(input[1] != "D" && input[1] != "W" && input[1] !=
"I" && input[1] != "T" && input[1] != "G")
{
return 0;
}
else if(input[1] == "I")
{
if((input[2] == "S" || input[2] == "L" || input[2] == "A") && input.length == 3)
{
return 1;
}
}
else if(input[1] == "T")
{
if(amount > 0 && input.length == 5)
{
if(input[3] == "S" || input[3] == "L"
|| input[3] == "A" || input[3] == "C")
{
if(input[4] == "S" || input[4] == "L"
|| input[4] == "A" || input[4] == "C")
{
return -1;
}
}
}
}
else if(amount > 0 && input.length == 4)
{
if(input[3] == "S" || input[3] == "L"
|| input[3] == "A" || input[3] == "C")
{
return 2;
}
}
return 0;
}
public static void processTransaction(Customer myCust, int whatTran, String[] input)
{
Double amount = Double.valueOf(input[3]);
if(whatTran == 1)
{
switch(input[2].charAt(0))
{
case 'S': myCust.savAcct.applyInterest();
break;
case 'L': myCust.loanAcct.applyInterest();
break;
case 'A': myCust.autoLoanAcct.applyInterest();
break;
}
}
else if(whatTran == 2)
{
}
else if(whatTran == -1)
{
}
}
}