HTW Berlin Medieninformatik HTW Berlin
Fachbereich 4
Internationaler Studiengang
Internationale Medieninformatik (Bachelor)
Info 1: Informatik I
Summer Term 2014
Laboratory 2: 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 see the idea of modularization, that is, splitting up code into 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. Read the ClockDisplay code in order to see how it uses the NumberDisplay class that we spoke about in the lecture yesterday. Open up BlueJ and play with it to see how it works. Explain in your report how the hours increase.
  2. Now adapt the ClockDisplay to display the time American-style (i.e. 12-hour clock and am / pm). You will have to include the Strings "am" or "pm" in the display!
  3. There are at least two ways in which you could have implemented exercise 2—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 exercise 2, implement the other in a new class. Which one was better? Why?
  4. 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.
  5. (For the bored) Research Threads and make the clock increment automatically every second.
  6. (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.


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


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