import java.io.*; import java.net.*; class BankServer { public static void main(String[] args) throws IOException { final int PORT = 12345; //Prepare the input and output streams in order to exchange info with the client ObjectOutputStream outputToClient; ObjectInputStream inputFromClient; //The server needs to listen to a port before any connection can be //established ServerSocket serverSocket = new ServerSocket(PORT); System.out.println("Server is listening to port " + PORT); System.out.println(""); //After listening to a port, the server also needs to constantly //be listening for a connection from a client Socket connectToClient = serverSocket.accept(); //Create data input and output streams outputToClient = new ObjectOutputStream(connectToClient.getOutputStream()); inputFromClient = new ObjectInputStream(connectToClient.getInputStream()); Bank newBank = Bank.getInstance(); // create advisors Advisor a1 = new Advisor("Main","Howard"); Advisor a2 = new Advisor("Fisher","Games"); newBank.addAdvisor(a1); newBank.addAdvisor(a2); // create new customer with checking account, balance 0 Customer c1 = new Customer("Kellie","Smith"); Customer c3 = new Customer("John","Smith"); CheckingAccount ca2 = new CheckingAccount(c3, 0.0); CheckingAccount ca1 = new CheckingAccount(c1, 0.0); ca2.addPerson(c3); newBank.addBankAccount(ca1); System.out.println("Account created: "); System.out.println("=============================="); System.out.println("Account type: Checking Account "); System.out.println("Account Number: " + ca1.getAccountNumber()); System.out.println("Owner: " + c1.getFirstName() + c1.getLastName()); System.out.println("Advisor: " + a1.getFirstName() + a1.getLastName()); System.out.println("Balance is: " + ca1.getBalance()); System.out.println("=============================="); System.out.println(""); // create new customer with saving account, balance 0 Customer c2 = new Customer("Tom","Brown"); SavingAccount sa1 = new SavingAccount(c2, 0.0); newBank.addBankAccount(sa1); System.out.println("Account created: "); System.out.println("=============================="); System.out.println("Account type: Saving Account "); System.out.println("Account Number: " + sa1.getAccountNumber()); System.out.println("Owner: " + c2.getFirstName()); System.out.println("Balance is: " + sa1.getBalance()); System.out.println("=============================="); System.out.println(""); while(true) { try { String question = (String) inputFromClient.readObject(); System.out.println("Waiting for clients to connect...."); System.out.println("Received: " + question); if(question.equals("quit")) //added { break; } BankService service = new BankService(newBank); String answer = service.doService(question); outputToClient.writeObject(answer); System.out.println(""); System.out.println("Saving Account Number: " + sa1.getAccountNumber()); System.out.println("Balance is: " + sa1.getBalance()); System.out.println(""); System.out.println("Checking Account Number: " + ca1.getAccountNumber()); System.out.println("Balance is: " + ca1.getBalance()); System.out.println(""); }catch(Exception ex){}; } } }