3 // Author: Danish Lakhani
5 // BankAppServer - Bank Application Server that services one client at a time
11 class BankAppClientTeller
13 static int SUCCESS = 0;
16 static int LOGIN_ACCOUNT = 1;
17 static int LOGIN_PIN = 2;
19 static int ACCOUNT_SAVINGS = 1;
20 static int ACCOUNT_CHECKING = 2;
21 static int ACCOUNT_TELLER = 3;
23 private Socket mySocket = null;
24 private PrintWriter out = null;
25 private BufferedReader in = null;
26 private static int serverPort = 44444;
28 public BankAppClientTeller()
32 private void establishConnection()
35 System.out.println("Connecting to server...");
36 mySocket = new Socket("localhost", serverPort);
37 out = new PrintWriter(mySocket.getOutputStream(), true);
38 in = new BufferedReader(new InputStreamReader(mySocket.getInputStream()));
39 System.out.println("Connection Established!");
42 private void closeConnection()
53 private void displayMenu()
55 System.out.println("\nBankAppClientTeller");
56 System.out.println("----------------");
57 System.out.println("1. Login");
58 System.out.println("2. Logout");
59 System.out.println("3. Deposit");
60 System.out.println("4. Withdraw");
61 System.out.println("5. Check Balance");
62 System.out.println("6. Open Account");
63 System.out.println("7. Close Account");
64 System.out.println("8. Modify Account");
65 System.out.println("9. Check Account Info");
66 System.out.println("0. Exit\n");
67 System.out.print("Enter Choice: ");
71 private void startClient()
77 boolean loggedIn = false;
78 BufferedReader local_in = new BufferedReader(new InputStreamReader(System.in));
79 while (clientQuit == 0)
82 establishConnection();
84 while (isConnected == 1)
87 String input = local_in.readLine();
88 int selection = Integer.parseInt(input);
93 System.out.println("Exitting...");
98 System.out.println("Login");
100 response = in.readLine();
101 if (response.equals("OK"))
103 System.out.print("Enter account number: ");
104 String accountNumber = local_in.readLine();
105 System.out.print("Enter PIN: ");
106 String pinNumber = local_in.readLine();
107 out.println(accountNumber);
108 out.println(pinNumber);
109 response = in.readLine();
110 if (response.equals(accountNumber))
112 System.out.println("Login Successful! Account: " + response);
117 System.out.println(response);
122 System.out.println(response);
126 System.out.println("Logout");
127 out.println("LOGOUT");
128 response = in.readLine();
129 if (response.equals("OK"))
131 response = in.readLine();
132 System.out.println("Logout Successful! Account: " + response);
136 System.out.println(response);
140 System.out.println("Deposit");
141 out.println("TELLERDEPOSIT");
142 response = in.readLine();
143 if (response.equals("OK"))
145 System.out.print("Enter Account Number: ");
146 String accNum = local_in.readLine();
148 response = in.readLine();
149 if (!response.equals("OK"))
151 System.out.println(response);
154 System.out.print("Enter Deposit Amount: ");
155 String depAmount = local_in.readLine();
156 out.println(depAmount);
157 response = in.readLine();
158 if (response.equals("OK"))
160 response = in.readLine();
163 System.out.println(response);
166 System.out.println("Withdraw");
167 out.println("TELLERWITHDRAW");
168 response = in.readLine();
169 if (response.equals("OK"))
171 System.out.print("Enter Account Number: ");
172 String accNum = local_in.readLine();
174 response = in.readLine();
175 if (!response.equals("OK"))
177 System.out.println(response);
180 System.out.print("Enter Withdrawal Amount: ");
181 String wdAmount = local_in.readLine();
182 out.println(wdAmount);
183 response = in.readLine();
184 if (response.equals("OK"))
186 response = in.readLine();
189 System.out.println(response);
192 System.out.println("Check Balance");
193 out.println("TELLERCHECK");
194 response = in.readLine();
195 if (response.equals("OK"))
197 System.out.print("Enter Account Number: ");
198 String accNum = local_in.readLine();
200 response = in.readLine();
201 if (!response.equals("OK"))
203 System.out.println(response);
206 response = in.readLine();
208 System.out.println(response);
211 System.out.println("Account Open");
212 out.println("TELLEROPEN");
213 response = in.readLine();
214 if (!response.equals("OK"))
216 System.out.println(response);
219 System.out.print("Enter Account Number: ");
220 out.println(local_in.readLine());
221 System.out.print("Enter First Name: ");
222 out.println(local_in.readLine());
223 System.out.print("Enter Middle Name: ");
224 out.println(local_in.readLine());
225 System.out.print("Enter Last Name: ");
226 out.println(local_in.readLine());
227 System.out.print("Enter Account Type: ");
228 out.println(local_in.readLine());
229 System.out.print("Enter Initial Balance: ");
230 out.println(local_in.readLine());
231 System.out.print("Enter PIN: ");
232 out.println(local_in.readLine());
233 response = in.readLine();
234 if (response.equals("OK"))
235 response = in.readLine();
236 System.out.println(response);
239 System.out.println("Account Close");
240 out.println("TELLERCLOSE");
241 response = in.readLine();
242 if (!response.equals("OK"))
244 System.out.println(response);
247 System.out.print("Enter Account Number: ");
248 out.println(local_in.readLine());
249 response = in.readLine();
250 if (response.equals("OK"))
251 response = in.readLine();
252 System.out.println(response);
255 System.out.println("Modify Account");
256 out.println("TELLERMODIFY");
257 response = in.readLine();
258 if (!response.equals("OK"))
260 System.out.println(response);
263 System.out.print("Enter Account Number: ");
264 String accNum = local_in.readLine();
266 response = in.readLine();
267 if (!response.equals("OK"))
269 System.out.println(response);
275 System.out.println("1. Change Name");
276 System.out.println("2. Change Type");
277 System.out.println("3. Change PIN");
278 System.out.println("4. Change Balance");
279 System.out.println("5. Done\n");
280 System.out.print("Enter Choice: ");
281 int choice = Integer.parseInt(local_in.readLine());
285 out.println("CHANGENAME");
286 System.out.print("Enter New First Name: ");
287 out.println(local_in.readLine());
288 System.out.print("Enter New Middle Name: ");
289 out.println(local_in.readLine());
290 System.out.print("Enter New Last Name: ");
291 out.println(local_in.readLine());
292 response = in.readLine();
293 if (!response.equals("OK"))
295 System.out.println(response);
299 out.println("CHANGETYPE");
300 System.out.print("Enter New Account Type: ");
301 out.println(local_in.readLine());
302 response = in.readLine();
303 if (!response.equals("OK"))
305 System.out.println(response);
309 out.println("CHANGEPIN");
310 System.out.print("Enter New PIN: ");
311 out.println(local_in.readLine());
312 response = in.readLine();
313 if (!response.equals("OK"))
315 System.out.println(response);
319 out.println("CHANGEBALANCE");
320 System.out.print("Enter New Balance: ");
321 out.println(local_in.readLine());
322 response = in.readLine();
323 if (!response.equals("OK"))
325 System.out.println(response);
333 System.out.println("Invalid selection");
337 response = in.readLine();
338 System.out.println(response);
341 System.out.println("View Account");
342 out.println("TELLERVIEW");
343 response = in.readLine();
344 if (!response.equals("OK"))
346 System.out.println(response);
349 System.out.print("Enter Account Number: ");
350 String accNumber = local_in.readLine();
351 out.println(accNumber);
352 response = in.readLine();
353 if (response.equals("OK"))
354 response = in.readLine();
355 System.out.println(response);
358 System.out.println("Invalid Selection");
361 System.out.println("Press Enter to Continue...");
367 public static void main(String [] args)
370 System.out.println("BankAppClientTeller in Java");
371 BankAppClientTeller client = new BankAppClientTeller();
372 client.startClient();