The main purpose of this lab exercise is to:
modify the clock-display project so it shows 12-hour time, rather than 24-hour time
test your modifications with test in an Examples class
How to get started
Login to one of the Linux machines in the classroom.
Create a subdirectory under cs102 for this lab:
$ cd cs102
$ mkdir lab3
Copy the starter project for this lab:
$ cp -r /home/cs102/bluej/projects/chapter03/clock-display/ ./lab3
Launch BlueJ and open up your clock-display project for this lab.
Java Exercises
Even though I know you all have your BlueJ text with you for this lab, I’m also including here the description taken from exercises 3.31 and 3.32 on p. 81:
Change the clock from a 24-hour clock to a 12-hour clock. Be careful: This is not as easy as it might at first seem. In a 12-hour clock, the hours after midnight and after noon are not shown as 00:30, but as 12:30. Thus, the minute display shows values from 0 to 59, while the hour display shows values from 1 to 12!
There are (at least) two ways in which you can make a 12-hour clock.
One possibility is to just store hour values from 1 to 12.
This is the way we are modifying the clock-display project for this lab.
No other approach to solving this problem is permitted for the purposes of this lab (you will get to use a second approach when working on assignment 2)
Hints:
all the changes you need to make are in class ClockDisplay; not NumberDisplay
you need to modify both constructors to create the required hours number display
you need to modify the updateDisplay method so that it displays 12-hour time
Add an Examples class to test your modified clock display.
here is my Examples class from Wednesday’s lecture (renamed
ClockDisplayExamples). The tests it contains won’t pass for a 12-hour ClockDisplay, but this gives you a head-start for modifying/adding the tests you need
you should test the roll-over times, when minutes roll-over, and when hours roll over
interesting roll-overs to test include 11:59 to 12:00, and 12:59 to 01:00
be prepared to convince yourself (and me or the coaches) that you’ve tested your 12-hour clock sufficiently!
When you’ve completed the above exercises, alert Marc or one of our coaches to take a look, and check you off as having completed the lab. After you are checked off, follow the submit procedure detailed below.
Submitting your work
From a terminal window, type the following commands at the Linux prompt:
cd
cd cs102
submit102 lab3
Log out
When you are done, close BlueJ and logout. Always remember to log out when you are finished using the system, to ensure that no one else uses your account.