|
by 
[Help |
API Docs |
Short Course|
Exercises]
For this exercise you add several instance variables and methods for handling open and closed conditions to MusicStore.
Prerequisites
Skeleton Code
Tasks
Add the instance variables openTime and closeTime to MusicStore. The data types should be int and the initial values should be reasonable times such as 9 and 21 (9 AM to 9 PM in 24-hour time), or something similar.
Add four access methods for the integer-based open and closing time variables: setOpen, getOpen, setClose, and getClose.
Add a method that returns the appropriate boolean value for whether the store is currently open or closed: isOpen. The method should compare the instance variables openTime and closeTime with the current system time. You will use the provided getHourInt instance method of AltDate to obtain the current hour (0..24).
Add the convenience method getOpenClosedMessage. It should return a String value stating whether the store is currently open or closed, based on the current system time and the openTime and closeTime instance variables.
For now, modify the method displayHoursOfOperation so that it reports the arbitrary (hard-coded) opening and closing times you specified when initializing the openTime and closeTime instance variables.
Add functionality to TestMusicStore to display a message such as "We're Open!" or "We're Closed!".
Compile the source code for MusicStore and TestMusicStore.
Execute TestMusicStore.
Where help exists, the task numbers above are linked to the step-by-step help page.
Solution Source
Demonstration
The output should be similar to the following, either on the command line or in an IDE window:
We're Open!
Store Hours:
Daily: 9:00 AM - 21:00 PM
Roberto Baggio, Proprietor
Copyright 1996-2000 jGuru.com. All Rights Reserved.
|
|