File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Just Java 2 clock class help required (Resolved) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Just Java 2 clock class help required (Resolved)" Watch "Just Java 2 clock class help required (Resolved)" New topic
Author

Just Java 2 clock class help required (Resolved)

Stuart Smith
Ranch Hand

Joined: Mar 28, 2008
Posts: 54
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 ]

Dale Carnegie:<br />"Most of the important things in the world have been accomplished<br />by people who have kept on trying when there seemed to be no hope at all."
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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."


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

By the way, you might also consider using a switch/case statement.
Stuart Smith
Ranch Hand

Joined: Mar 28, 2008
Posts: 54
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

Joined: Mar 28, 2008
Posts: 54
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

Joined: Aug 31, 2004
Posts: 11343

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

Joined: Mar 28, 2008
Posts: 54
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Just Java 2 clock class help required (Resolved)