SE1011
Class Exercises

UML Class Diagram

+---------------------------------------+
|                 Mouse                 |   <== Class name
+---------------------------------------+
| daysOld: int                          |
| weight: double                        |   <== Attributes/object variables
| growthRate: double                    |
+---------------------------------------+
| setGrowthRate(rate: double): void     |
| grow(): void                          |   <== Behaviors/methods
| display(): void                       |
+---------------------------------------+

Exercise 1: Mouse Modifications

Modify the Mouse class developed in lecture as follows. Assume that a mouse object mickey exists:

  1. Make it possible to say mickey.setName("Mickey"); and have the name Mickey display when mickey.display(); is called.
  2. Make it possible to say mickey.grow(3); and have the mouse age by three days (instead of just one as is done with mickey.grow();).
  3. Create an accessor that returns the mouse's current weight.
  4. Create an accessor that returns the mouse's current age (in days).
  5. Create an accessor that returns the mouse's current growth rate.
  6. Create a mutator that sets the mouse's current growth rate.

Exercise 2: Using the Mouse class

Create a driver program that asks the user to enter the name and growth rate for a mouse and displays characteristics for the mouse at the end of each week of growth for its first year of life.

Create a driver program that asks the user to enter an integer, desiredMice and then does the same thing as above, except for desiredMice mouse objects.

Last modified: Tuesday, 16-Feb-2016 10:54:10 EST