• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Nested if's

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am supposed tochange this from a nested if to something else but I don't know what else to changed it to any help would be appricated.

 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could implement it usning enums.
 
Victoria Preston
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think he wanted me to get rid of the if's all together...doesn't emun's use ifs
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could use a HashMap with the timezones as keys and the minutes as Integer values.
[ March 31, 2006: Message edited by: Joanne Neal ]
 
Victoria Preston
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
whats a hashmap
 
Sheriff
Posts: 28328
96
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or if this is a real-life question and not just a beginner's programming exercise, you could replace the whole thing by calls to various methods in the TimeZone class. No "ifs" would be required there.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You dont have to use if's if you use enums. You could use the valueOf() method.

 
Victoria Preston
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I am in intermidate programming but its the beginner stuff I don't understand.....I am having trouble with the basic concepts...thats why I post here
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Map approach is something I use all the time. Look at the JavaDoc for all the details. Here's a method that might be similar to yours:

See if you can read up on HashMap enough to do somethin glike that.
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like the perfect fit for the Strategy Design Pattern. Some proponents of language theory proclaim that a single if/else is a broken construct and does not belong in a complete language. While I haven't bought that argument just yet, I certainly agree with the more wider (though still small relative to the critical mass) understanding that a if/else/else (3 or more statement bodies) should always be avoided. I even know a few who claim that for loops are flawed constructs!! I haven't bought that argument, simply because I don't understand it in completeness yet, but I suspect that they are ultimately right. For the same reason - appropriate abstraction/accurate requirement expression - switch/case constructs should always be avoided.

The point being, I suspect that your teacher (a knowledagable academic?) is probably trying to teach you something related to this and I encourage you to pursue it further.

The Strategy Design Pattern - one of few legitimate design patterns - is implemented in Java almost always using a java.util.Map. If you wish to go for further purity (but falling infinitely short implied by Java), you might want to consider net.tmorris.adt.map.Map - or just write the interface yourself. Minimalism is paramount even though it is often unachievable under a given context. So often I observe suffering as a result of excessive expression of requirement/contract, and worse, I observe the resulting "problem" attributed to a consequence, instead of the underlying flaws.

Good to hear of a tertiary institution on the right path ...if indeed that is what is happening.
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Tony Morris:
Good to hear of a tertiary institution on the right path ...if indeed that is what is happening.



For all we know the instructor is trying to push them towards a type-safe enum and a switch/case so I wouldn't get my hopes up too much.

As for the OP's question, I think using a Map is your best bet and someone already gave you sample code for that.
 
permaculture is largely about replacing oil with people. And one tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic