import java.util.*; public class BankService { BankAccount account = null; public BankService(BankAccount theAccount) { account = theAccount; //setting the account } public String doService(String answer) { Bank bank = Bank.getInstance(); /* when the user enters the command depsoit * this will deposit the specified into the accountnumber they * want */ if(answer.indexOf("deposit") >=0) { StringTokenizer token = new StringTokenizer(answer); token.nextToken(); String accNumber = token.nextToken(); int num = Integer.parseInt( accNumber ); check = bank.getAccountByNumber(num); if(check==null) { System.out.println("You have entered an invalid account number"); } else { String number = token.nextToken(); int depNum = Integer.parseInt( number ); check.deposit(depNum); } answer = "" + num; } /* when the user enters the command withdraw * this will withdraw the specified from the accountnumber they * want */ else if (answer.indexOf("withdraw")>=0) { StringTokenizer token = new StringTokenizer(answer); token.nextToken(); String accNumber = token.nextToken(); int num = Integer.parseInt( accNumber ); check = bank.getAccountByNumber(num); if (check==null) { System.out.println("You have entered an invalid account number"); } else { String number = token.nextToken(); int withNum = Integer.parseInt( number); check.withdraw(withNum); } answer = "" + num; } else if (answer.indexOf("balance")>=0) { //is this actually returning the balance of the number the enter? StringTokenizer token = new StringTokenizer(answer); token.nextToken(); String accNumber = token.nextToken(); int num = Integer.parseInt( accNumber ); check = bank.getAccountByNumber(num); if (check==null) { System.out.println("You have entered an invalid account number"); } else { String number = token.nextToken(); int balNum = Integer.parseInt( number ); System.out.println("Your balance is : " + check.getBalance()); } } else //if the command entered is invalid return this { answer = "Sorry, I don't understand this request."; } return answer; } }