Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Just Java 2 clock class help required (Resolved)

 
Stuart Smith
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there I have managed to get the clock to display Roman numerals, there is not a zero in Roman numerals so my questions are:

At midnight using the 24 hour clock the time would be 0:0:00

1. How could I change the clock to use 12 hours instead?
2. What can I do instead of using zero?

All of this must be done in the ClockViewRoman.java file.

ClockViewRoman.java



clockRoman.java



TimeStamp.java


[ April 02, 2008: Message edited by: Stuart Smith ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stuart Smith:
...
1. How could I change the clock to use 12 hours instead?
2. What can I do instead of using zero? ...

One approach would be to have a field for a mode setting (12 or 24 hour). If the mode is 12-hour, then do something clever with the modulo operator (%).

As for the zero hour... I don't know. That's a placeholder the Roman system didn't use. One option might be to display "nulla."
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, you might also consider using a switch/case statement.
 
Stuart Smith
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by marc weber:

One approach would be to have a field for a mode setting (12 or 24 hour). If the mode is 12-hour, then do something clever with the modulo operator (%).

As for the zero hour... I don't know. That's a placeholder the Roman system didn't use. One option might be to display "nulla."


Thanks for the nulla info I shall update the code to display N

I chose to use if rather than the switch statement as each if can be on one line. hmm thinking about it switch probbly could be to but when I first wrote this code using proper switch code layout it was well long.

Not sure how to use modulo to get it to display 12 hours instead of 24 but I shall have a try and see what happens.

Thanks
 
Stuart Smith
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could not get the modulo % idea to work but this does work now what do you think of my if not really long sollution?

Added a boolean to toggle 12-24 hours

Introduced an if else to refreshTimeDisplay() to modify the 24 hours into 12

Modified the if's to a switch

1. Any reasons you said to use switch instead of if?


[ March 30, 2008: Message edited by: Stuart Smith ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stuart Smith:
Could not get the modulo % idea to work...

...
case 13: tHours = "I"; break; // 13%12 is 1
case 14: tHours = "II"; break; // 14%12 is 2
case 15: tHours = "III"; break; //15%12 is 3
...
[ March 30, 2008: Message edited by: marc weber ]
 
Stuart Smith
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by marc weber:

...
case 13: tHours = "I"; break; // 13%12 is 1
case 14: tHours = "II"; break; // 14%12 is 2
case 15: tHours = "III"; break; //15%12 is 3
...



lol thanks for all your help and for not giving me the answer so I can think about it and get it right myself.

The simple anwsers always get me

I will rewrite it to simplify at some point and going to ad command line arguments to modify the 12-24 mode and probbly a button also.

Thanks again =)
[ March 30, 2008: Message edited by: Stuart Smith ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic