319
- a. What are the two places in which data abstraction is visible to the user?
b.Should publicconstants be initialized in their declarations or in assignment
statements?
c. Can variables be marked as publicin Java?
Programming Warm-Up Exercises
1.Write a CRC card for a class, Car, representing an automobile with its make,
model, color, and license plate number.
2.Write a CRC card for a subclass of the automobile class in Exercise 1, called
RentalCar, that adds a responsibility for taking trip mileage and rental days val-
ues and computing a rental cost. Extend the responsibility for creating an
object of this class to include specification of the cost per mile and cost per day.
3.Write a CRC card for a class, Book, representing a library book. It should
support creating a book with a title, author, and call number, and knowing each
of these values.
4.Write a CRC card that is a subclass of the Book class developed in Exercise 3,
called LoanRecord. It adds the capability to record a patron ID number and a
due date for the book, and to determine whether the book is overdue.
5.Write a CRC card for a subclass of LoanRecord (Exercise 4) that allows the inclu-
sion of library ID number for interlibrary loans. Also add the ability to indicate,
when an object is created, if it is not available for interlibrary lending. Provide a
responsibility to test for this property of an object.
6.Write a CRC card for a class, Cow, representing a cow in a dairy herd. The class
should include a name, an ID number, a date of birth, and a date of most recent
calving.
7.Write a CRC card for a subclass of Cow (Exercise 6) that adds the ability to keep
a total of milk output, to enter a value for a milking, and to compute average
milk production. The subclass should also support the ability to reset the total
milk output value to zero.
8.Brainstorm a set of classes for the following problem statement: You are creat-
ing an application that records progress in a fitness program. For each user of
the program, you should keep track of the person’s initial weight, quarter-mile
jog time, standing long-jump distance, and bench-press weight. After each
training session, new values are entered for each of these measurements, and
the difference from the original values is displayed. The total number of
sessions should also be counted.
9.Filter the classes that were brainstormed in Exercise 8.
10.Write CRC cards for the classes that remain after the filtering in Exercise 9.
Include the initial responsibilities.