CS1027b Computer Science Fundamentals II

Lab 5

Learning Outcomes

Upon completion of this lab, you should be able to do the following:

General Lab Instructions

IMPORTANT. Make sure you attend the lab session to which you registered, show the result(s) of each exercise to your TA, and submit the .java files that you wrote and AnswersLab5.txt through OWL by 11:55pm on the same day as your lab session to get your marks for the lab.

Exercise 1: Creating another subclass of BankAccount

Create a new project for the classes BankAccount and CheckingAccount.

Create a new SavingsAccount class in your project, which extends the class BankAccount (how should you declare this class?). Besides the instance variables and methods inherited from class BankAccount, this class must contain one instance variable of type double called interestRate. We might need to create several objects of the new class SavingsAccount, each one with its own balance and interest rate. Should instance variable interestRate be declared as static. Write your answer in AnswersLab5.txt; you must explain your answer.

This class must also contain the following methods:

Exercise 2: Experimenting with inheritance

Download the file TestBankAccounts.java and add it to your project. This class has a main method that creates several bank account objects of the three types BankAccount, CheckingAccount, and SavingsAccount.

In each step of this exercise, you will be adding statements to the main method, running it after each addition. Answer the questions at each step and write your answers in AnswersLab5. If there is a compilation error, make sure you comment out the offending statement before advancing to the next step of this exercise.

Make the following changes to class TestBankAccounts (code must be added near the end of the main method, after the last comment line):

Exercise 3: Experimenting with polymorphism

Download the file BankMachine.java and add it to your project.