Main { (@ static public void main(String args[]) throws Exception { BrokerSim b = new BrokerSim(); // print welcome message b.set_marketList(MarketList.parse(new FileInputStream("../../Broker.mar"))); b.set_accountList(AccountList.parse(new FileInputStream("../../Broker.acc"))); b.set_operationList(OperationList.parse(new FileInputStream("../../Broker.op"))); // BrokerSim b = BrokerSim.parse(new FileInputStream("../../Broker.input")); b.run(); } @) } BrokerSim { (@ void run() throws Exception { Account a = new Account(); Username u = new Username(); Password p = new Password(); Password pv = new Password(); Cash c = new Cash(); BufferedReader inputLine; String input = new String(); boolean operational = true; boolean flag = true; a = null; while(operational) { while (a == null) { System.out.println("\n\n------------------------------"); System.out.println("Log On to the Brokerage System"); System.out.println("------------------------------\n"); System.out.print("Username : "); inputLine = new BufferedReader (new InputStreamReader(System.in)); input = inputLine.readLine(); u = new Username(input); if (input.equals("exit")) { System.out.println("see ya"); exit_Broker(); operational = false; break; // will have to update Broker.input with Market, Account & Op list... // maybe have oplist in separate file } a = check_Username(u); if (a != null) { System.out.print("Password : "); inputLine = new BufferedReader (new InputStreamReader(System.in)); input = inputLine.readLine(); if (input.equals(a.get_password().get_pword())) { loggedOn(a); } else { System.out.println("\nInvalid Password"); a = null; } } else { System.out.println("\nThat Username is not in our database"); System.out.print("Would you like to create a new Account? (y/n)"); input = inputLine.readLine(); if (input.equals("y")) { System.out.print("Enter a password for this account : "); input = inputLine.readLine(); p.set_pword(input); c.set_amount(10000); a = new Account(); a.set_username(u); a.set_password(p); a.set_cash(c); accountList.get_aclist().addElement(a); loggedOn(a); } // create new Account // Remember to addElement to the List(Account)... } } } } @) } BrokerSim { void loggedOn(Account a) throws Exception (@ Operation current_operation = new Invalid(); OpCode quit_opcode = new OpCode("Quit"); OpCode input_opcode = new OpCode(); BufferedReader inputLine; String input = new String(); System.out.println("\nWelcome! Time to start making some $$$ :-) \n"); while (current_operation.get_opCode() != quit_opcode) { show_Operations(); System.out.print("\nSo what's your pleasure : "); inputLine = new BufferedReader (new InputStreamReader(System.in)); input = inputLine.readLine(); input_opcode.set_o(input); current_operation = find_Operation(input_opcode); break; } @) } BrokerSim { traversal checkAccount (CheckUsernameVisitor cv) { through AccountList to Username; } Account check_Username(Username username) (@ Account a = new Account(); CheckUsernameVisitor cv = new CheckUsernameVisitor(); cv.set_username(username); this.checkAccount(cv); a = cv.get_return_val(); return a; @) } BrokerSim { traversal allOperations (DisplayOpVisitor dv) { to {Buy, Sell, MarketReport, AccountReport, Quit}; } void show_Operations() (@ DisplayOpVisitor dv = new DisplayOpVisitor(); this.allOperations(dv); @) } BrokerSim { traversal findOperations (FindOpVisitor fv) { to {Buy, Sell, MarketReport, AccountReport, Quit}; } Operation find_Operation(OpCode o) (@ Operation op; FindOpVisitor fv = new FindOpVisitor(); fv.set_opcode(o); this.findOperations(fv); op = fv.get_return_val(); return op; @) } BrokerSim { void exit_Broker() throws Exception (@ get_accountList().write_file(); get_marketList().write_file(); @) } AccountList { traversal allAccounts (FileVisitor fv) { through {AccountList} to *; } void write_file() throws Exception (@ PrintWriter acc = new PrintWriter(new FileOutputStream("../../Broker.acc")); FileVisitor fv = new FileVisitor(acc); this.allAccounts(fv); acc.close(); @) } MarketList { traversal allInvestments (FileVisitor fv) { through {MarketList} to *; } void write_file() throws Exception (@ PrintWriter mar = new PrintWriter(new FileOutputStream("../../Broker.mar")); FileVisitor fv = new FileVisitor(mar); this.allInvestments(fv); mar.close(); @) } FileVisitor { before AccountList (@ file.println("("); @) before Username (@ file.print("Username: \"" + host.get_uname() + "\" "); @) before Password (@ file.print("Password: \"" + host.get_pword() + "\" "); @) before Cash (@ file.print("$ " + host.get_amount()); @) before MarketList (@ file.println("("); @) before TickerSymbol (@ file.print("* \"" + host.get_ttsymbol() + "\" "); @) before UnitValue (@ file.print("$ " + host.get_value() + " "); @) before Shares (@ file.print("# " + host.get_shares() + " "); @) before Description (@ file.print("\"" + host.get_desc() + "\""); @) before Portfolio (@ file.println("[ ("); @) after Account (@ file.println(); @) after AccountList (@ file.println(")"); @) after Investment (@ file.println(); @) after MarketList (@ file.println(")"); @) after Portfolio (@ file.println(") ]"); @) } // b.set_operationList(MarketList.parse(new FileInputStream("../../Broker.op")); CheckUsernameVisitor { init (@ account = null; @) before Account (@ caccount = host; @) before Username (@ if (host.get_uname().equals(username.get_uname())) { account = caccount; } @) return Account (@ account @) } FindOpVisitor { init (@ operation = new Invalid(); @) before Operation (@ if (opcode.get_o().equals(host.get_opCode().get_o())) { operation = host; } @) return Operation (@ operation @) } DisplayOpVisitor { before BrokerSim (@ System.out.println("---------------------------"); System.out.println("Please choose an operation:"); System.out.println("---------------------------\n"); @) before Operation (@ System.out.println(host.get_opCode().get_o() + "\t" + host.get_opDesc().get_desc()); @) }