ICS 141 Programming with Objects

Program #5

 

Part I:  Class Hierarchy Due Tuesday, March 16 (10 points)

 

CLASS HIERARCHY COVER SHEET

 

Points Possible

Points

Earned

 

Comments

Design (10 pts):

D1:  Solution has three or more classes arranged in an inheritance hierarchy plus a testing class

D2: Class diagram includes methods, data and data types

D3:  Relationship between classes is correctly shown

 

 

 

 

 

 

 

Part II:  Implementation of Program Due Tuesday, March 23 (40 points)

 


ICS 141 Programming with Objects

Program #5

Part II:  Implementation of Program

Due Tuesday, March 23, 2004

40 points

 

IMPLEMENTATION COVER SHEET

Style (5 pts):

S1: Program comments

S2: Indenting and aligning

S3: Meaningful names

S4: Efficient code

 

 

Implementation (35 pts):

I1: (5 pts) Program has at least three classes arranged in an inheritance hierarchy.  Program correctly uses inheritance

I2: (2 pts) Topmost class has at least two attributes

I3: (4 pts) Topmost class has get and set methods for each attribute

I4: (1 pt) Topmost class has constructor(s)

I5: (1 pt) Topmost class has toString() method

I6: (2 pts) Topmost class has at least two more methods

I7: (2 pts) Second and third classes each have an additional attribute

I8: (4 pts) Second and third classes each have set and get methods for the additional attribute

I9: (2 pts) Second and third classes have at least one more method

I10: (2 pts) Second and third classes have toString() method

I11: (5 pts) One method in either the second or third class is polymorphic

I12: (5 pts) Test program calls each method and demonstrates that it works properly

I3: Output is attractive

 

 

I understand that I must turn in original and individual work.  I have not allowed anyone else to see my code.  I have not used someone else's work.

 

_____________________________________________________________________

Signature                                                                      Date

 

Print name here:  _______________________________________________________

 

 

Goals: To understand and use inheritance and polymorphism

 

Problem statement:  Think up an inheritance hierarchy that has at least three classes.  One example using four classes (which you may NOT use) is given below:

 

 

 

Animal

 

 

String gender

int numLegs

 

 

Animal()

Animal ( String gen, int legs)

void setGender( String )

String getGender ()

void setNumLegs ( int )

int getNumLegs ()

String toString()

void speaks()

void moves()

 

 

 

 

 

 

 

 

 

 

Mammal

 

Reptile

String color

 

int numEggs

Mammal()

Mammal ( String gen, int numLegs, String color)

void setColor ( String )

String getColor()

String toString()

void moves()

 

Reptile()

Reptile ( String gen, int numEggs)

void setEggs ( int )

int getEggs ()

String toString()

void moves()

void hatchesEggs()

 

 

 

 

 

 

 

 

Dog

 

 

String breed

 

Dog ()

Dog ( String gen, int numLegs, String color, String breed)

void setBreed ( String )

String getBreed ()

String toString()

void barks()

void runs()

 

 

 

 

Come up with at least two attributes for the topmost class and at least one additional attribute for each of the other classes.  Come up with at least two behaviors (in addition to setting and getting each attribute, the constructors and toString()) for the topmost class and at least one additional behavior for each of the child classes.

 

Additional requirements:

1.       At least one of the behaviors should be polymorphic.

2.      Use public, private and protected access modifiers correctly.

 

Write code for each of the classes.  Provide appropriate constructors, and get and set methods to change or get at the attributes for objects.  Write a testing class which contains main().  The testing class must instantiate at least one object of each class.  It must demonstrate the use of each method you’ve implemented, including the polymorphic method(s).

 

You may NOT choose any of the following:  Animal, Pet, Bank Account, Person, Employee, Shape, Vehicle or any other example given in your textbook.

 

You may use one of these suggestions or you may make up your own:  Literature (Book, Magazine), Clock (Alarm Clock, Electric Clock), Building (Shop, Office, House), Dwelling (House, Apartment), Plant (Flower, Tree, Shrub), Computer (Laptop, Desktop), Product, etc. 

 

The design:

Use at least two levels of inheritance, including at least three classes involved in the inheritance hierarchy plus a testing class. You must use inheritance and polymorphism to solve this problem to receive full credit.

 

Draw the class diagram.  Note that the class diagram is due one week before the program is due.

 

Do screen captures of at least one of the program’s runs.

 

Include comments in your programs.  At a minimum, include the following information at the top of every file:

 

Your name:

Date:

Name of the class:

Brief description of the class:

 

Include additional comments as needed to make the program clearly understandable.

 

Turn in:

1. The cover sheet for this assignment.

2. A diskette containing your source code.  DO NOT EMAIL YOUR SOLUTION TO ME.  Your diskette should contain only work for this assignment.  Label your diskette (or CD) with your name.

3. Print outs of your source code.

4. Print outs of at least one run of your program (use screen capture).

5. The class diagram.