• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

need some help on indentifier

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic