Lab 3

For this lab you will use an existing bank account class that has already been written for you. Download this zip file and notice that it contains .h and .m files for the BankAccount class. There will be two parts for this lab. You will be asked to submit zip files for two different projects.

Part I

Create a Single-View project called BankAccountTester, with a single "Go" button. Create an action connection for the button. In the associated method, you will test the BankAccount class. You will need to do the following
  1. Drag BankAccount.h and BankAccount.m onto the project folder.
  2. In ViewController.m, import "BankAccount.h"
  3. In the method associated to the button, add code that creates 3 BankAccount objects and carries out transactions on these objects. The first few lines of this code are provided below:
        BankAccount *b1 = [BankAccount alloc];
        BankAccount *b2 = [[BankAccount alloc] init];
        BankAccount *b3 = [[BankAccount alloc] initWithAmt:1000];
    
        NSLog(@"Balances are now b1:%6.2f b2:%6.2f b3:%6.2f\n",
              b1.balance, b2.balance, b3.balance);
    
    Now, add more code that does the following (the actual code is not provided this time; you will need to supply these): We have done something similar with the Car class in the last lecture session, so you could use that exercise as a guide. When done, zip the project folder, rename the zip file to Lab3Part1-idnumber.zip and submit via moodle.

Part II

Create an app (called BankApp) that carries out deposits and withdrawals from a single bank account. This is an actual app with visual controls. Specifically, it will contain a label that facilitates the display of the bank account's balance, a text field through which the user will specify a transaction amount, and two buttons (labeled Withdraw and Deposit) that carry out the transactions. Refer to the following progression of screenshots:
image image image

Follow these instructions closely, in the specified order.
  1. After adding the controls, create action connections from the buttons and outlet connections from the label and the text field. I will assume that the outlet connections are called display and amount (you may name these something else).
  2. Drag BankAccount.h and BankAccount.m onto the project folder.
  3. In ViewController.h, add this import statement
    #import "BankAccount.h"
    
    and the following property:
    @property BankAccount *bankAccount;
    
    This will be the object that the app will work with and through which transactions will be carried out.
  4. In ViewController.m, inside the method called viewDidLoad, add the following code (right before the }):
        self.bankAccount = [[BankAccount alloc] initWithAmt:1000];
        NSString *s =[NSString stringWithFormat:@"Balance is now %6.2f",self.bankAccount.balance];
        self.display.text = s;
    
    The above code creates the BankAccount object and displays the initial balance.
  5. Still in ViewController.m, in the method associated with the Withdraw button, insert the following code:
        double amt = [self.amount.text doubleValue];
        [self.bankAccount withdrawAmt:amt];
        NSString *s =[NSString stringWithFormat:@"Balance is now %6.2f",self.bankAccount.balance];
        self.display.text = s;
    
  6. Do something similar for the Deposit button.
  7. Test your app.
When done, zip the project folder, rename the zip file to Lab3Part2-idnumber.zip and submit via moodle.