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:
- Make it possible to say
mickey.setName("Mickey");
and have the name Mickey display whenmickey.display();
is called. - Make it possible to say
mickey.grow(3);
and have the mouse age by three days (instead of just one as is done withmickey.grow();
). - Create an accessor that returns the mouse's current weight.
- Create an accessor that returns the mouse's current age (in days).
- Create an accessor that returns the mouse's current growth rate.
- 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