public String toString() { return "[type=" + getName() + "][locationId=" + getLocationId() + "][size=" + getSize().toString() + "][twStart=" + Activities.round(getTheoreticalEarliestOperationStartTime()) + "][twEnd=" + Activities.round(getTheoreticalLatestOperationStartTime()) + "]"; }
@Override public void execute() { String readIn; System.out.println("Please choose account type:"); System.out.println("Type 1: Checking account"); System.out.println("Type 2: Saving account"); HashMap<Integer, String> accountType = new HashMap<Integer, String>(); accountType.put(1, "Checking"); accountType.put(2, "Saving"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try { readIn = br.readLine(); try { int type = Integer.parseInt(readIn); // get account type BankApp.currentAccounts.put(currentId, Activities.create(type)); // create account System.out.printf("Create %s Account with ID: %d", accountType.get(type), currentId); currentId++; } catch (Exception e) { System.out.println("Fail to Create"); } } catch (IOException e) { System.out.println("Read Error, please try again."); } }
@Override public void execute() { String readIn; System.out.println("Please type account ID and deposit amount:"); System.out.println("Format: accountID,amount"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try { readIn = br.readLine(); try { String[] input = readIn.trim().split(","); int accountID = Integer.parseInt(input[0]); // get the accountID int amountInt = Integer.parseInt(input[1]); // get the deposit amount Money amount = new Money(amountInt); // put the amount in Money object System.out.print("Before Deposit: "); BankApp.currentAccounts.get(accountID).print(); // print account info Activities.depositTo(BankApp.currentAccounts.get(accountID), amount); // make deposit System.out.print("After Deposit: "); BankApp.currentAccounts.get(accountID).print(); } catch (Exception e) { System.out.println("Fail to deposit."); } } catch (IOException e) { System.out.println("Read Error, please try again."); } }
@Override public void execute() { String readIn; System.out.println("Please type account ID and withdraw amount:"); System.out.println("Format: FromAccountID,ToAccountID,amount"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try { readIn = br.readLine(); try { String[] input = readIn.trim().split(","); int fromAccountID = Integer.parseInt(input[0]); // transfer from this account int toAccountID = Integer.parseInt(input[1]); // transfer into this account int amountInt = Integer.parseInt(input[2]); // get the transfer amount Money amount = new Money(amountInt); // put the amount in Money object System.out.println("Before Transfer: "); System.out.printf(" From Account %d: ", fromAccountID); BankApp.currentAccounts.get(fromAccountID).print(); // print account into System.out.printf(" To Account %d: ", toAccountID); BankApp.currentAccounts.get(toAccountID).print(); if (Activities.transfer( BankApp.currentAccounts.get(fromAccountID), BankApp.currentAccounts.get(toAccountID), amount)) { // make transfer // if transfer succeed, print info System.out.println("After Transfer: "); System.out.printf(" From Account %d: ", fromAccountID); BankApp.currentAccounts.get(fromAccountID).print(); System.out.printf(" To Account %d: ", toAccountID); BankApp.currentAccounts.get(toAccountID).print(); } } catch (Exception e) { System.out.println("Fail to transfer."); } } catch (IOException e) { System.out.println("Read Error, please try again."); } }