CSCI 180/181 Spring 2008, Lab 3 - Due 2/4 at 11:59 pm

Today we'll spend hands-on time getting used to dealing with classes that use objects defined by other classes (which we also define). Our objectives are to get familiarity with the conventions of using objects inside of classes, and then to write a class that uses objects inside of it.

  1. Open the clock-display project.
  2. To implement a 12-hour clock, modify the ClockDisplay class as follows:
    • add a private field boolean twelveHourDisplay that is initialized to false by the constructor.
    • modify the private void updateDisplay() method to set the display string to a 12-hour time (with a.m. and p.m.) if twelveHourDisplay is true.
    • add a method public void toggleDisplay() that flips the value of twelveHourDisplay (i.e. from true to false or false to true).  The method should also call updateDisplay() so that the current display reflects the correct type of time (12-hour or 24-hour)
  3. In the clock-display project, create a new class called NewsroomClock that uses two ClockDisplay objects to keep track of the current time in both Cincinnati and the time in another city.  Also include a field called clock2City of type String that contains the name of the second city. Do not change the ClockDisplay or NumberDisplay classes beyond the changes in exercise 2 above. Provide the following methods:
    • public NewsroomClock(int clock1Hour, int clock1Minute, int clock2Hour, int clock2Minute, String city) -- initializes the Cincinnati clock time (using the first two parameters) and the second city’s clock (using parameters 3 and 4).  Also initializes clock2City to city
    • public NewsroomClock(int clockHour, int clockMinute) -- initializes the Cincinnati time to the given hour and minutes, sets the second city clock to one hour earlier and the city string to “Chicago.”
    • public void setClock1(int hour, int minutes) sets the Cincinnati time.
    • public void setClock2(int hour, int minutes, String city) sets the second city time and clock2City string.
    • public void timeTick() increments the current time in both cities by one minute.
    • public void toggleDisplay() that toggles the display of the Cincinnati and second city time between 12-hour and 24-hour time.
    • public String getClock2() returns the second city time.
    • public String getClock1() returns the Cincinnati time.
    • public void displayTime() prints both times along with appropriate titles specifying the cities for each

Use the style guide on our home page for the labs from now on as well as the projects.
Hand in your modified ClockDisplay.java and the NewsroomClock.java file with
handin 180 lab3 ClockDisplay.java NewsroomClock.java.