HTW Berlin Medieninformatik HTW Berlin
Fachbereich 4
Internationaler Studiengang
Internationale Medieninformatik (Bachelor)
Info 1: Informatik I
Winter Term 2022/23
Laboratory 3: Rock around the Clock

Pre-lab

This week's lab work is intended to get you to implement parts of a class that is given for you. You are also to begin to understand the idea of modularization, that is, splitting up code into multiple classes.

What to Bring to Lab

Please bring these exercises printed out or written out with you to lab. Please have your name on your page.

P1. Which of the following expressions returns true? After writing your answers on paper, open the CodePad in BlueJ and try it out.

Expression
! (4 < 5)
! false
(2>2) || ((4==4) && (1<0))
(2>2) || (4==4) && (1<0)
(34 != 33) && !false
(43 < 42) && (rabbitCount > dogCount)
test = (3 < 4)

P2. Write an expression using boolean variables a and b that evaluates to true when either a and b are both true or both false.

P3. Write an expression using boolean variables a and b that evaluates to true when only one of a and b is true, and which is false if a and b are both true or both false. This is called the exclusive-or.

P4. Consider the expression (a && b). Write an equivalent expression (one that evaluates to true at exactly the same values for a and b) without using the && operator.

P5. Americans are kind of strange about numbers and units. They write the days backwards, they use pounds and inches instead of kilograms and centimeters, and they have this bizarre 12-hour clock they use with "am" and "pm". What time is "12 am" on the German (24-hour) clock? What time is "12 pm"? What time is "3 am"? What time is "5:30 pm"?

 

Post-Lab, AKA  What To Turn In

Your completed assignment, submitted in Moodle as a pdf, should include:

Lab assignments are due before your next lab at 22:00. They may, of course, be turned in earlier. You hand them in by preparing the report in PDF and submitting it to Moodle.


Assignment

Clock time

  1. Download the ClockDisplay project from Moodle.
  2. Read the ClockDisplay code in order to see how it uses the NumberDisplay class that we spoke about in the lecture. Open up BlueJ and play with it to see how it works. Explain in your report in complete sentences how the hours increase.
  3. Now adapt the ClockDisplay to display the time American-style (i.e. 12-hour clock with the hours and minutes separated by a colon (":") and am / pm). You will have to include the Strings "am" or "pm" in the display! I strongly suggest researching how American time is kept before you start programming.
  4. There are at least two ways in which you could have implemented the previous step—one keeps the time internally as a 24-hour clock and adapts the output, the other keeps the time internally as it is displayed. Whichever way you chose for the previous step, now implement the other in a new class.
  5. Which implementation was better? Why?
  6. Make your clock into an alarm clock by adding an alarm. You should be able to set the alarm time and turn the alarm on and off. When the clock reaches the alarm time, it should ring—writing "Riiiiiiiing!" to the terminal is sufficient.
  7. (For the bored) Use the MusicPlayer from the MusicOrganizer project to play some music (or a ringing sound) instead of writing to the terminal.
  8. (For the really bored) Research Threads and make the clock increment automatically every second.
  9. (For the extremely bored) Make a clock GUI, display all three hands, and play an appropriate melody when the alarm rings. You might as well set the colon to blink on and off every second. Make sure the rights to the sounds you use are okay, don't steal licensed music.

Writeup

Submit your writeup as your post-lab to the Moodle area by 22:00 the evening before your next lab.


Copyright Prof. Dr. Debora Weber-Wulff
Questions or comments: <weberwu@htw-berlin.de>
Some rights reserved. CC-BY-NC-SA - Copyright and Warranty

The exercises are adapted from Objects First with Java, A Practical Introduction Using BlueJ. David Barnes & Michael Kölling, 2016