• Post Reply Bookmark Topic Watch Topic
  • New Topic

need some help on indentifier  RSS feed

 
Sally Curtis
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello, i am writing a class that recieves a army time(800, 2400, ect) and assigns it a medicine that should be taken... i want my constructor to make int clock equal to the time the is sent to the class. how would i do that?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Long case statements like that always sound an alarm to me. They're a little hard to follow and could easily be a site of frequent change. So, how else can we associate a time with one or more meds?
If the times are strictly on the hour, you might make a 24-slot array and put the meds for 12:00 midnight in slot 0, 1:00 in slot 1, etc. You'd have to convert 800 to 8 for example, but that sounds pretty easy.
Another way to associate things is a Map. Maybe something like:

I suspect you are BRAND new to Java because of a number of syntax problems in your code, so I suggest you write the smallest possible piece of running code you can manage and work from there. Feel free to post your progress for more help!
BTW: If you don't have a bookmark for the JDK docs, make one now! http://java.sun.com/j2se/1.4/docs/api/index.html You can look and see how Map works for you. Like, why did I make the time a String?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!