• 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
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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: 27465
88
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.
 
If you want to look young and thin, hang around old, fat people. Or this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic