JAVA 1 Class, NEED HELP
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: JAVA 1 Class, NEED HELP

Hybrid View

  1. #1
    Join Date
    Oct 2011
    Posts
    8

    Question JAVA 1 Class, NEED HELP

    I am looking for advise the answer.

    I am in a JAVA 1 programing class online and right now we are working on a 24 to 12 hour clock conversion. We are only able to change the timeTick method, the constructors and the setTime

    Here is where I am at

    [code]

    /**
    * The ClockDisplay class implements a digital clock display for a
    * 12 hour clock. The clock shows hours and minutes. The
    * range of the clock is 12:00am (midnight) to 11:59pm (one minute before
    * midnight).
    *
    * The clock display receives "ticks" (via the timeTick 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 Kolling and David J. Barnes
    * @version 2008.03.30
    *
    * Tyler Hord
    * Modafications:
    */
    public class ClockDisplay
    {
    private NumberDisplay hours;
    private NumberDisplay minutes;
    private String displayString; // simulates the actual display

    /**
    * Constructor for ClockDisplay objects. This constructor
    * creates a new clock set at 12:00.
    */
    public ClockDisplay()
    {
    hours = new NumberDisplay(12);
    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(12);
    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();
    if(updateDisplay() == "00:00"){
    return "12:00";}
    }

    /**
    * 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();
    }
    }
    [code]

    Please help. Advise or ideas only please no answers.

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: JAVA 1 Class, NEED HELP

    Duplicate post. See this thread
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center