# Chalenge exercise - I need help

Page 1 of 1

## 4 Replies - 1203 Views - Last Post: 15 June 2009 - 12:38 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=110103&amp;s=d4722a5eb218a6b61bfc38f4298461e4&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 novich1

Reputation: 0
• Posts: 14
• Joined: 06-June 09

# Chalenge exercise - I need help

Posted 15 June 2009 - 08:24 AM

Change the clock from a 24-hour clock to a 12-
hour clock.

```public class ClockDisplay

{
private NumberDisplay hours;
private NumberDisplay minutes;
private String displayString;	// simulates the actual display
public ClockDisplay()
{
hours = new NumberDisplay(1-12);
minutes = new NumberDisplay(0-59);
updateDisplay();
}
public ClockDisplay(int hour, int minute)
{
hours = new NumberDisplay(1-12);
minutes = new NumberDisplay(0-59);
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;
}

/**
* Update the internal string that represents the display.
*/
private void updateDisplay()
{
displayString = hours.getDisplayValue() + ":" +
minutes.getDisplayValue();
}
public String getDisplayValue(String value)
{
value = displayString;
return  value + " ";
}

}

```

I think i make some mistake somewhere,but i can't find him?

Is This A Good Question/Topic? 0

## Replies To: Chalenge exercise - I need help

### #2 jjsaw5

• I must break you

Reputation: 88
• Posts: 3,056
• Joined: 04-January 08

## Re: Chalenge exercise - I need help

Posted 15 June 2009 - 08:33 AM

Could you please provide us with some more information. Like any error messages or a description of what your code is not doing that it is supposed to.

Thank you!

### #3 novich1

Reputation: 0
• Posts: 14
• Joined: 06-June 09

## Re: Chalenge exercise - I need help

Posted 15 June 2009 - 08:41 AM

There is no error messages but when i call String get.Display.value and insert "01:22"and expect to receive same result i receive "00:00".I use BlueJ.

### #4 n00bc0der

Reputation: 3
• Posts: 62
• Joined: 27-November 08

## Re: Chalenge exercise - I need help

Posted 15 June 2009 - 11:38 AM

Your code is a mess and it's not all here.... I can't even help you because I need to see the rest of the code to figure out what's wrong.

### #5 NeoTifa

• ¿Dónde están mis pantalones?

Reputation: 1973
• Posts: 14,489
• Joined: 24-September 08

## Re: Chalenge exercise - I need help

Posted 15 June 2009 - 12:38 PM

I would do your tick method after your set time method. Have an algorithm for detecting am and pm. Say if hours > 12, then hours - 12 is currentHour or something. Also, check to make sure nobody puts in something funky like 25:76 for the time. Roll it over maybe. 60 == 00, so 76 == 16. Hope that helped a little.