General Questions to Answer in High-level Design of a Class
1. What tasks will the object perform?
2. What information will it need to perform its tasks?
3. What methods will it use to process its information?
4. What information will it make public for other objects?
5. What information will it hide from other objects?
D1. Identify the data for the class.
D2. Identify appropriate behaviors. Some include:
D3. For each behavior in 2, design its interface.
D4. Design the algorithm to achieve each behavior. (Verify the algorithm on paper.)
I3. Return to step I1 or D4 as necessary until the result of I2 is satisfactory.
A rectangle has two attributes, height and width (both real number values). A user may need to: create Rectangle objects by providing a height and a width; get the area or perimeter of a rectangle object, set or get the width or the height.
Design the Rectangle class.
A CyberPet does one of two things: either sleep or eat, based on what the user tells it to do. When the user tells it to sleep (or eat), it simply reports that it is sleeping (or eating). The user may also want to find out the current state of a CyberPet – that is, whether it is sleeping or eating. A CyberPet has a name that is set on creation and may be changed or retrieved by a user.
Include a “toString()” method that prints out both a CyberPet’s name and state.
Please note: the CyberPet may be extended later to include other activities beyond sleeping and eating, so design with this in mind.
Design the CyberPet class.