• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

Just Java 2 clock class help required (Resolved)

 
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 ]
 
Sheriff
Posts: 11343
Mac Safari Java
  • 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
Mac Safari Java
  • 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
Mac Safari Java
  • 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 ]
 
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic