Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

NumberDisplay: Modify ClockDisplay to accommodate a 12-hour clock in addition to the 24-hour clock Rules: You must not change the storage from current 24-hour clock

image text in transcribed

image text in transcribed

image text in transcribed

NumberDisplay:

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Modify ClockDisplay to accommodate a 12-hour clock in addition to the 24-hour clock Rules:

  1. You must not change the storage from current 24-hour clock values

  2. You must not modify NumberDisplay

To implement a 12-hour clock, modify the ClockDisplay class as follows:

  • add a private field boolean twelveHourDisplay that is initialized to false in the constructors.

  • add a method public void toggleDisplay() that flips/toggles 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) .

    a. Access type public b. Return type void c. Parameters none d. Logic toggle twelveHourDisplay and call updateDisplay()

  • 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. Think of cases on the 24-hour clock and how they translate into the 12-hour clock.

ClockDisplay X Compile Undo Cut Copy Paste Find... Close Source Code /** * The ClockDisplay class implements a digital clock display for a * European-style 24 hour clock. The clock shows hours and minutes. The * range of the clock is 00:00 (midnight) to 23:59 (one minute before * midnight) * The clock display receives "ticks" (via the time Tick method) every minute * and reacts by incrementing the display. This is done in the usual clock * fashion: the hour increments when the minutes roll over to zero. * @author Michael Klling and David J. Barnes * @version 2016.02.29 */ public class ClockDisplay private NumberDisplay hours; private NumberDisplay minutes; private String displayString; 1/ simulates the actual display * Constructor for ClockDisplay objects. This constructor * creates a new clock set at 00:00. */ public ClockDisplay() hours = new Number Display (24); minutes = new NumberDisplay(60); updateDisplay(); /** * Constructor for ClockDisplay objects. This constructor * creates a new clock set at the time specified by the * parameters. */ public ClockDisplay(int hour, int minute) hours = new NumberDisplay (24); minutes = new NumberDisplay (60); setTime(hour, minute); /** * This method should get called once every minute - it makes * the clock display go one minute forward. */ public void timeTick() minutes.increment ; if(minutes.getValue() == 0) { // it just rolled over! hours.increment(); updateDisplay(); I** * Set the time of the display to the specified hour and * minute */ public void setTime(int hour, int minute) hours.setValue(hour); minutes.setValue(minute); updateDisplay(); ** * Return the current time of this display in the format HH:MM. public String getTime() return displayString; ** * Update the internal string that represents the display. */ private void updateDisplay displayString = hours.getDisplayValue() + ":" + minutes.getDisplayValue(); /** * The NumberDisplay class represents a digital number display that can hold * values from zero to a given limit. The limit can be specified when creating * the display. The values range from zero (inclusive) to limit-1. If used, * for example, for the seconds on a digital clock, the limit would be 60, * resulting in display values from 0 to 59. When incremented, the display * automatically rolls over to zero when reaching the limit. * @author Michael Klling and David J. Barnes * @version 2016.02.29 11 public class Number Display private int limit; private int value; * * * Constructor for objects of class Number Display. * Set the limit at which the display rolls over. */ public NumberDisplay(int rolloverLimit) limit = rolloverLimit; value = 0; * Return the current value. */ public int getValue() return value; * Return the display value (that is, the current value as a two-digit * String. If the value is less than ten, it will be padded with a leading * zero). public String getDisplayValue() if(value = 0 && (replacementValue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions