Courses‎ > ‎AP Computer Science‎ > ‎Konstantinovich‎ > ‎notes‎ > ‎

2017-10-03

posted Oct 3, 2017, 6:23 AM by Konstantinovich Samuel   [ updated Oct 3, 2017, 10:21 AM ]
SENIORS:
On Thursday Mike Zamansky, the father of StuyCS, will be coming by to talk about Hunter College’s Deadalus Honors CS Program. It is a great local and inexpensive option for college CS that Mike has been building out over the past 2 years. He will be giving in class talks periods 7-10 (all softdev classes and one systems class), and will also be giving the same talk after 10th for anyone that could not make it earlier. Since periods 8-10 will be in 307, which has extra room, you are welcome to stop by then if you’re in 4th or 5th period systems and have one of those periods free, otherwise, come by after 10th.

Today's Highlights:
Completing a basic object.
Short Circuit Evaluation.
Boolean return values and their usage.


public class DriverBankAccount{
  public static void main(String[]args){
    BankAccount b1 = new BankAccount(1000.0, 1000001, "abc123");
    BankAccount b2 = new BankAccount(1234.0, 1000231, "abcasdg23");

    System.out.println("Account b1:");
    System.out.println(b1);
    System.out.println("Account b2:");
    System.out.println(b2);
    System.out.println();


    double cashAmount = 300.0;
    while(cashAmount < 3000){
      System.out.println("Attempt to move "+cashAmount+" from the b1 to b2 account:");
      if(b1.withdraw(cashAmount) ){
        if(b2.deposit(cashAmount)){
          System.out.println("Success");
        }else{
          //This should never happen.
          //Error message provided to make sure that is the case
          System.out.println(cashAmount + " withdrawn from" +
                             b1 + "Failed to add to "+b2);
        }
      }else{
        System.out.println("Failed to withdraw "+cashAmount+" from "+b1);
      }

      System.out.println("Account b1:");
      System.out.println(b1);
      System.out.println("Account b2:");
      System.out.println(b2);
      System.out.println();
      cashAmount *= 2;
    }
  }
}

Notice how clunky this process is?
Assignment:
1. Take your bank account and test it with my driver.
2. Add the following methods:

/*This private method will allow internal methods to check the password easily*/
private boolean authenticate(String password)

/**Transfer money from this BankAccount to the other. 
 *@param other which BankAccount to GIVE the money to
 *@param amount how much money to transfer, negative amounts will make this operation fail.
 *@param the password of the source account, incorrect password will make this operation fail.
 *@return true if successful, false otherwise.
 */
public boolean transferTo(BankAccount other, double amount, String password)

Comments