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();
Person p = new Person();
// create new customer with checking account, balance 0
Customer c1 = new Customer("Kellie","Smith");
CheckingAccount ca1 = new CheckingAccount(c1, 0.0);
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("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: " + p.getFirstName() + p.getLastName());
System.out.println("Balance is: " + sa1.getBalance());
System.out.println("==============================");
System.out.println("");
// create advisors
Advisor a1 = new Advisor("Main","Howard");
Advisor a2 = new Advisor("Fisher","Games");
newBank.addAdvisor(a1);
newBank.addAdvisor(a2);
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){};
}
}
}