This assignment is based on Exercises 3.31 and 3.32 from the BlueJ textbook. In addition, you will implement a method that toggles the clock’s display between 12- and 24-hour time. Of course, you will need to test your code in the Examples class.
Prep
assign2 directory under your cs102 course directory. This is the directory in which you will create your BlueJ project.
$ cp -r /home/cs102/bluej/projects/chapter03/clock-display/ ~/cs102/assign2/
Tasks
Exercises 3.31 and 3.32 are really one exercise. 3.31 is more informational, and 3.32 asks you to implement something.
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. (We took the first approach in Lab 3, but now we’re going to start over and implement these changes differently.) For this assignment, implement a 12-hour clock that leaves the clock to work internally as a 24-hour clock but changes the display string of the clock display to show 04:23am when the internal value is 04:23, or 04:23pm when the internal value is 16:23.
Which implementation approach (Lab 3 or this assignment) is better? Why? Think about this, but don’t answer yet.
Finally, implement a method to toggle the clock display between 12- and 24-hour time. This will require:
boolean field to class ClockDisplay to indicate 12- or 24-hour time: display24
ClockDisplay to toggle the display format: toggleDisplay()
updateDisplay method
One more time: Which implementation approach (Lab 3 or this assignment) is better? Why? Did you change your mind? Answer this question in the notes file for your project.
Don’t forget to add an Examples class to your project (you could copy your Examples class from Lab 3), and include sufficient tests for correctly printing 12-hour time, as well as toggling the 12- and 24-hour displays.
Once you have completed the above exercises, all the tests you added in your Examples class pass, and your name is in the header comments for all your *.java files:
submit102 script