Chalenge exercise - I need help

clock Display - Change the clock from a 24-hour clock to a 12- hour cl

Page 1 of 1

4 Replies - 1203 Views - Last Post: 15 June 2009 - 12:38 PM Rate Topic: -----

#1 novich1  Icon User is offline

  • New D.I.C Head

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

Chalenge exercise - I need help

Post icon  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?


***added code tags -jjsaw5***

Is This A Good Question/Topic? 0
  • +

Replies To: Chalenge exercise - I need help

#2 jjsaw5  Icon User is offline

  • I must break you
  • member icon

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

Re: Chalenge exercise - I need help

Posted 15 June 2009 - 08:33 AM

:code:



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.


Remember the more information you provide us with the better we will be able to help you.


Thank you!
Was This Post Helpful? 0
  • +
  • -

#3 novich1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#4 n00bc0der  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#5 NeoTifa  Icon User is offline

  • ¿Dónde están mis pantalones?
  • member icon





Reputation: 1973
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1