-
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;
}
}
-
Re: clock
what is the problem and what is Number Display in the above code?
-
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();
}
}
-
Re: clock
I think your variable is "value" not "Value", right?
-
Re: clock
thank you, it worked now :D
-
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);
-
Re: clock
Which method? which line? What is the error? Detail....Detail...
-
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
-
Re: clock
what compiler say about the error?
-
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.
-
Re: clock
cannot find symbol - method SetTime(int,int); maybe you ment getTime or setTime(int,int)
-
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.