Exercise 3.1 Given a class hierarchy to represent information about people at a university, including the classes Person, Instructor, and Staff:
design class Student to be a new subclass of the Class Person. It should contain information about the student's GPA and major.
Develop the method withHonors, which determines whether the student's GPA is greater than 3.5
Complete the test suite for this collection of classes.
Complete the UML diagram for this collection of classes.
Exercise 3.2 Given a UML class hierarchy to represent items in the grocery store, develop the classes Grocery, Coffee, Juice, and IceCream as specified in the UML diagram.
Exercise 3.3 Develop a class hierarchy to represent three different types of vehicles: cars, trucks, and buses. For all vehicles we need to record the size of the fuel tank in gallons, and the estimated fuel consumption given in miles per gallon. Just like the class Car in an earlier exercise, we can compute:
the maximum distance the vehicle can travel on one tank of fuel
whether it can travel a given distance
whether it can travel farther than some other vehicle.
Exercise 3.4 Warning: This exercise can
be completed independently of the previous exercise.
Develop a
class hierarchy to represent three different types of vehicles:
cars, trucks, and buses. Different kinds of vehicles need to
represent additional information as follows:
A car may or may not pull a trailer.
A bus can carry some number of passengers (capacity) and has some number of passengers on board.
A truck has some specified maximum load and some current load.
Develop the method computeToll, which will compute the toll for each vehicle according to the following rules:
A car without a trailer pays $0.25 per mile.
A car towing a trailer pays $0.35 per mile.
A bus pays $0.35 per mile and additional $0.20 for each passenger.
A truck pays $0.40 per mile and in addition $0.05 for each 1000 lb of load it currently carries.
Exercise 3.5
Create a class to represent the address of some person. Address should include the street, the city, the state and the zip code.
Extend the class hierarchy from Exercise 3.1, so that it records the address for each kind of person (Person, Instructor, Staff).
Develop the method thisZip, which determines whether this person lives in a given zip code.
Draw the UML diagram for this collection of classes.
Exercise 3.6
Modify the class InventoryItem from Exercise 2.6 to represent the inventory information about any grocery item in the class hierarchy from Exercise 3.2.
Draw the UML diagram for this collection of classes.
Explain briefly how the method grossIncome performs the calculations.
Explain briefly how the method betterPriceThan performs the calculation, when we choose to compare a Coffee item with an IceCream item.