HI all ok here I get a problem I am trying to change a 24 clock display to 12 hours displays but some how my code dosen't compile help need it if anyone know how to do this please let ok here is my code I just don't know whats wrong with it
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();
}
/**
* 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();
}
public function clock() {
if (getDisplay) return;
hours = getHours();
minutes = getMinutes();
amOrPm = "AM";
if (hours > 11) amOrPm = "PM";
if (hours > 12) hours = hours - 12;
if (hours == 0) hours = 12;
if (minutes <= 9) minutes = "0" + minutes;
if (seconds <= 9) seconds = "0" + seconds;
dispTime = "<span class='datetime'>" + hours + ":" + minutes + ":" + seconds + " " + amOrPm + "</span>";
if (document.layers) {
document.layers.pendule.document.write(dispTime);
document.layers.pendule.document.close();
}
else
if (document.all)
pendule.innerHTML = dispTime;
setTimeout("clock()", 1000);
}
}
}
then I created another class for the number display here is code for it this one works fine:
public class NumberDisplay
{
private int limit;
private int value;
/**
* Constructor for objects of class Display
*/
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
* 12).
*/
public String getDisplayValue()
{
if(value < 10)
return "0" + value;
else
return "" + value;
}
/**
* Set the value of the display to the new specified value. If the new
* value is less than zero or over the limit, do nothing.
*/
public void setValue(int replacementValue)
{
if((replacementValue >= 0) && (replacementValue < limit))
value = replacementValue;
}
/**
* Increment the display value by one, rolling over to zero if the
* limit is reached.
*/
public void increment()
{
value = (value + 1) % limit;
}
}
Thats all I done and I still don't get it why it dosen't compile any help would be great thank you.
ya know...that code looks suspiciously like one of my homework assignments from this last semester...I might venture to say it looks exactly the same, in fact, down to the text of the comments used.
well...except for that public function clock() section, which is written in JavaScript instead of Java, and isn't in my copy of the program ^_^
take out that junk function and the extra } at the end and it should work
What you studying Cytael ? I am doing HND in computing and I get this clock thing from Java Blue J bood thats what we studying and this is one of our objective to understand how clocks works in java.
BTW what you mean remove the exter } if I do that I get this error ''connot resolve smboly - class function.
I think you've missed an open curly brace { for the else part in public function clock(). Include it and try to compile..of course, after changing the return type of clock().
HI guys again ok after going thourgh this again and again I still can't compile it. I changed alot of things but still won't compile ok here is what I have done so far:
public class ClockDisplay
{
private NumberDisplay hours;
private NumberDisplay minutes;
private String displayString; // simulates the actual display
private String amOrpm;
private String hour;
/**
* 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();
}
/**
* 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;
}
/**
* Get display in the format HH:MM.
*/
public String getDisplay()
{
return displayString;
}
/**
* Get Hour in the format HH:.
*/
public int getHours()
{
return hours.getValue();
}
/**
* Get Minutes in the format :MM.
*/
public int getMinutes()
{
return minutes.getValue();
}
/**
* Update the internal string that represents the display.
*/
private void updateDisplay()
{
displayString = hours.getDisplayValue() + ":" +
minutes.getDisplayValue();
}
I'm currently almost finished with a course in object-oriented analysis and design using that blueJ book as the main text.
check out that last function:
PHP Code:
public void clock()
{
// first off, this is JavaScript, not Java...note how the variables aren't declared
if (hours > 11) amOrPm = "PM";
} // <---- this guy is misplaced
else {
if (hours > 12) hours = hours - 12;
}
else {
if (hours == 0) hours = 12;
}
else {
if (minutes <= 9) minutes = "0" + minutes;
dispTime = "<span class='datetime'>" + hours + ":" + minutes + ":" + amOrPm + "</span>"; // <-- HTML doesn't work in Java :)
}
}
} // <-- that bracket isn't paired up with anything
take out that entire last part of your code and see what happens
Hello all, first time here ! ( Nice to meet all u happy bunch)
Nez2003 it looks like me and u are doing the same thing.
I also have to convert a 24HR clock in AM / PM
Also i have to create a alarm clock
So if u can help me that would be great !
And also to other people, Please help a brother out !
I have been working on this for 1 week now and i dont understant what the hell to do ( pulling my hair out ) and my coursework is in for tommorrow December 09 2005, so please people i am begging you, PLEASE HELP ME !
Bookmarks