Missouri State University Spring 2010 CSC 131-2

Lab 12, April13, 2010

Name: ______

Note: Besides this paper copy, this lab is also online on eccentric and at If you need help with any exercise, raise your hand.

Please remember to save your work, upload what you have done to your folder on eccentric server (You may create a subdirectory named lab12), and turn in this report to me. This lab is due at the start of the lab nextTuesdayApril20.

There are seven checking points in this lab.

Programming with Inheritance

A certain company has written a significant amount of code for a class called BankAccount that has many methods including the following:

// the only constructor for a BankAccount, takes as a parameter

// with information about initial deposit, etc

public BankAccount(double initialDeposit)

// record the given Debit

public void debit(double d)

// record the given Credit

public void credit(double c)

// returns the current balance in pennies

public double getBalance()

The constructor sets the initial balance. Assume that only the debit and credit methods change the balance. You are to design a new class called MinMaxAccount whose instances can be used in place of a BankAccount object but which include the extra behavior of remembering the minimum and maximum balances ever recorded for this account. It should have a single constructor that takes a parameter and it should include the following methods:

// returns the minimum balance in pennies

public int getMin()

// returns the maximum balance in pennies

public int getMax()

Project bankAccount contains some source codes you might need to complete this checking point.

When you are done, save your program and upload it to your eccentric\upload\CSC 131\002\abc123s folder.

Returning an object from a Method

Open the project Vehicle. This project includes three classes. One is Person which contains two data members, name and email. One is Vehicle class, which is used to model vehicle objects. It has two data members, production year and owner. Notice owner is an object of Person. The third class in this project is TestVechile class, which is a client program for Vehicle class.

Checking point 2. Please include an accessor to retrieve the owner person and a mutator to set the owner.

Please always remember to save the revised code. When you finish modification of this program. Upload it to your eccentric\upload\CSC 131\002\abc123s folder

Checking point 3: Please finish the method called isOlderThan() which tries to compare two vehicles, if the receiving object is older than the argument object, it will return true, otherwise return false. You may include this to refer the receiving object.

Checking point 4: Now, the Vehicle class only has one constructor with two parameters to accept the owner and year. Please add two more constructors to Vehicle class. One assigns default values to owner as null, year as -1. Another is a copy constructor with one parameter which is a Vehicle object. Practice overloaded constructors.

Checking point 5: Using this to improve overloaded constructors via avoiding repeated codes.

Checking point 6: Add a class method isOlderThan(), which has two parameters. Both parameters are Vehicle objects, compare them, if the first is older than the second, return true. Otherwise, return false.

Checking point 7: in TestVehicle class, create at least two Vehicle objects, practice calling instance method isOlderThan() and class method isOlderThan(). Display related information.

Please always remember to save the revised code. When you finish modification of this program. Upload it to your eccentric\upload\CSC 131\002\abc123s folder

1