Skip navigation
The Australian National University

Laboratory 10 - Object Oriented Programming

Aim

The aim of this lab is to get you familiar with object oriented programming in Matlab.

Preparation

Please go through the slides for lectures 25-27. This covers object oriented programming in Matlab. As well, read chapter 18 of the text book. This is accessible via the Lectures link. Use this to understand the concepts, but the syntax is out of date, so use the current syntax. Try out the examples covered in the lectures and the text book.

Tools

The only tool you will need is the matlab programming environment. To use this, you will need to logon to a computer in one of the Computer Science labs, open up a terminal window and type the following from the command line:

matlab
Also, download this zip file that contains some matlab oo scripts, which you will need for this lab.

Instructions

  1. The file bankAccount.m defines the bank account class as a value class. Change this to a handle class. What changes do you need to make to the methods of this class? This will mean that the checkingAccount class will also now become a handle class and appropriate changes will need to be made.
  2. The bank account class has been defined as a single file. Organize this in a folder called @bankAccount, using the directory structure mentioned in the lectures. See the oo programming section for an example.
  3. Create a child class of the bank account class called savingsAccount that has an overdraw feature instead of the monthly fee property of the checking account class. Add methods to get and set the overdraw amount, with the default value being $500. The set overdraw method should be private. Create a constructor method for this class, similar to that for the checking account class, that can take a starting balance and initial overdraw amount as parameters, if they are provided. Override the getBalance method in the parent bank account class by providing a new one that calls the parent's get balance method and then adds the overdraw amount to the balance and returns this amount.
  4. Add a display method to all the classes that will provide information about these classes to calling programs and the workspace. This method is called when the object is output as text. See here for an explanation.
  5. Create scripts to test the savings account class. What are the test cases that you will consider to ensure that everything is working properly? If you find that some cases result in errors, then modify your class to correct such cases.

Updated:  Thu Jan 17 13:56:50 EST 2013 / Responsible Officer:   JavaScript must be enabled to display this email address. / Page Contact:   JavaScript must be enabled to display this email address.