Results 1 to 12 of 12

Thread: clock

  1. #1
    zacake is offline Member
    Join Date
    Mar 2012
    Posts
    6
    Rep Power
    0

    Default clock

    Hi, I have been trying to get a java clock to work, but there is a problem with the number display and I don't know how to fix it. anybody who can help? BTW, I'm using BlueJ.
    Here is the code:

    public class NumberDisplay
    {
    private int limit;
    private int value;
    /**
    * Constructor for objects of class NumberDisplay
    */
    public NumberDisplay(int roll0verLimit)
    {
    limit = roll0verLimit;
    value = 0;
    }
    public int getValue()
    {
    return value;
    }
    public void setValue(int replacementValue)
    {
    if((replacementValue >= 0) &&
    (replacementValue < limit)){
    Value = replacementValue;
    }
    }
    public String getDisplayValue()
    {
    if(value < 10) {
    return "0" + value;
    }
    else {
    return "" + value;
    }
    }
    public void increment()
    {
    value = (value + 1) % limit;
    }
    }

  2. #2
    gauravfzd's Avatar
    gauravfzd is offline Member
    Join Date
    Oct 2010
    Location
    India
    Posts
    72
    Rep Power
    0

    Default Re: clock

    what is the problem and what is Number Display in the above code?

  3. #3
    zacake is offline Member
    Join Date
    Mar 2012
    Posts
    6
    Rep Power
    0

    Default Re: clock

    Value = replacementValue; this is the problem,
    I'm not sure what you mean by what is the number display, i copyed the code from a book. I have a clock display here though if that's what you are asking about:


    public class ClockDisplay
    {
    private NumberDisplay hours;
    private NumberDisplay minutes;
    private String displayString; //simulate the actual display
    public ClockDisplay()
    {
    hours = new NumberDisplay(24);
    minutes = new NumberDisplay(60);
    updateDisplay();
    }
    public ClockDisplay(int hour, int minute)
    {
    hours = new NumberDisplay(24);
    minutes = new NumberDisplay(60);
    SetTime(hour, minute);
    }
    public void timetick()
    {
    minutes.increment();
    if(minutes.getValue() == 0) {//it just rolled over!
    hours.increment();
    }
    updateDisplay();
    }
    public void setTime(int hour, int minute)
    {
    hours.setValue(hour);
    minutes.setValue(minute);
    updateDisplay();
    }
    public String getTime()
    {
    return displayString;
    }
    private void updateDisplay()
    {
    displayString = hours.getDisplayValue() + ":" +
    minutes.getDisplayValue();
    }
    }

  4. #4
    gauravfzd's Avatar
    gauravfzd is offline Member
    Join Date
    Oct 2010
    Location
    India
    Posts
    72
    Rep Power
    0

    Default Re: clock

    I think your variable is "value" not "Value", right?

  5. #5
    zacake is offline Member
    Join Date
    Mar 2012
    Posts
    6
    Rep Power
    0

    Default Re: clock

    thank you, it worked now :D

  6. #6
    zacake is offline Member
    Join Date
    Mar 2012
    Posts
    6
    Rep Power
    0

    Default Re: clock

    I have an error in the clock display now,
    public class ClockDisplay
    {
    private NumberDisplay hours;
    private NumberDisplay minutes;
    private String displayString; //simulate the actual display
    public ClockDisplay()
    {
    hours = new NumberDisplay(24);
    minutes = new NumberDisplay(60);
    updateDisplay();
    }
    public ClockDisplay(int hour, int minute)
    {
    hours = new NumberDisplay(24);
    minutes = new NumberDisplay(60);
    SetTime(hour, minute);
    }
    public void timetick()
    {
    minutes.increment();
    if(minutes.getValue() == 0) {//it just rolled over!
    hours.increment();
    }
    updateDisplay();
    }
    public void setTime(int hour, int minute)
    {
    hours.setValue(hour);
    minutes.setValue(minute);
    updateDisplay();
    }
    public String getTime()
    {
    return displayString;
    }
    private void updateDisplay()
    {
    displayString = hours.getDisplayValue() + ":" +
    minutes.getDisplayValue();
    }
    }

    the error is: SetTime(hour, minute);

  7. #7
    gauravfzd's Avatar
    gauravfzd is offline Member
    Join Date
    Oct 2010
    Location
    India
    Posts
    72
    Rep Power
    0

    Default Re: clock

    Which method? which line? What is the error? Detail....Detail...

  8. #8
    zacake is offline Member
    Join Date
    Mar 2012
    Posts
    6
    Rep Power
    0

    Default Re: clock

    I have an error in the clock display now,
    public class ClockDisplay
    {
    private NumberDisplay hours;
    private NumberDisplay minutes;
    private String displayString; //simulate the actual display
    public ClockDisplay()
    {
    hours = new NumberDisplay(24);
    minutes = new NumberDisplay(60);
    updateDisplay();
    }
    public ClockDisplay(int hour, int minute)
    {
    hours = new NumberDisplay(24);
    minutes = new NumberDisplay(60);
    SetTime(hour, minute);
    }
    public void timetick()
    {
    minutes.increment();
    if(minutes.getValue() == 0) {//it just rolled over!
    hours.increment();
    }
    updateDisplay();
    }
    public void setTime(int hour, int minute)
    {
    hours.setValue(hour);
    minutes.setValue(minute);
    updateDisplay();
    }
    public String getTime()
    {
    return displayString;
    }
    private void updateDisplay()
    {
    displayString = hours.getDisplayValue() + ":" +
    minutes.getDisplayValue();
    }
    }

    The error is marked in red

  9. #9
    gauravfzd's Avatar
    gauravfzd is offline Member
    Join Date
    Oct 2010
    Location
    India
    Posts
    72
    Rep Power
    0

    Default Re: clock

    what compiler say about the error?

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default Re: clock

    You need to give us the error messages in full, otherwise we're just guessing.
    Make it easy for us to help you.

    And please use [code] tags [/code] when posting code, for the same reason.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  11. #11
    zacake is offline Member
    Join Date
    Mar 2012
    Posts
    6
    Rep Power
    0

    Default Re: clock

    cannot find symbol - method SetTime(int,int); maybe you ment getTime or setTime(int,int)

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default Re: clock

    Well, that error message is pretty self-explanatory isn't it?
    There is no SetTime() method, so the compiler is offering you one of two similar choices that actually do exist.

    Note, Java is case-sensitive. SetTime <> setTime.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. 24 hour clock to 12 hour clock project.
    By bs3ac in forum New To Java
    Replies: 4
    Last Post: 01-08-2013, 10:10 AM
  2. help with clock
    By Bimz in forum New To Java
    Replies: 1
    Last Post: 09-26-2011, 01:50 PM
  3. System Clock
    By sehudson in forum New To Java
    Replies: 2
    Last Post: 04-12-2011, 03:34 PM
  4. Clock JavaBean
    By dns.gonz in forum AWT / Swing
    Replies: 9
    Last Post: 10-08-2010, 04:49 AM
  5. clock
    By ws6driver in forum New To Java
    Replies: 1
    Last Post: 07-31-2009, 04:15 AM

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
  •