Out: Oct 31, 2011
Due: Nov 7, 2010 – Start of Class
Reading: Liang, Ch 11 (8th ed); Ch 9, 10 (6th ed)
CENG 310: Lab 6 – SubClasses, ArrayLists
Implement and test the code for the following Programming Exercises from Liang Ch 11, 8th edition. Provide a Status Report on each. UML diagrams are not required.
- 11.1 – Implement the Triangle class as a subclass of GeometricObject. (5 marks)
- 11.2 – Implement subclasses for Student and Employee. Where the question says “Define the status as a constant” this means that you should create constants for each value: freshman, sophomore, junior and senior. The actual status for each student should be a member variable limitted to one of these for values. (5 marks) (For a bonus mark – look up the use of enum as a data type and use this for the student status.
- 11.3 Implement and test CheckingAccount and SavingsAccount classes as as sub-classes of Account. An overdraft limit refers to the minimum amount below zero that can be taken from the account. The problem indicates that each checking account has an extra field stating the lowest allowable amount in the account. Savings accounts have a minimum balance of zero. The checks on these values should all be inside member functions, not in the main routine where you write your tests. Also keep in mind that you should not allow a negative values for deposits or withdrawals, the value passed should be checked to make sure that they are >=0.
(5 marks) - 11.5. The question asks you to rewrite the Course class in Listing 10.6 using an ArrayList rather than an Array. The purpose of this is to give you a bit of practices in using ArrayLists. Note that only the internal implementation of the class will change, and none of the testing. The advantage of the ArrayList is that, unlike an array, it grows and shrinks automatically to be as big as you need it to be, within the limits of total available memory. (2)
- 11.6 This is a slight rephrasing of the problem. Write a program that creates an ArrayList and adds a variety of different objects of different types using objects created from different classes that you’ve created in this or other assignments. Using a foreach loop iterate through all of items in the list. Invoke the toString() method for each, using the getClass() method report on the class to which each one belongs. (3)