... this looks an awful lot like a homework assignment ...
Joined: Jul 11, 2001
Originally posted by Melinda Wilson: Can any part of this code sample be furthered condensed?
Yes. Basically you are having a mapping between Strings and ints.
Than you can easily use the Map to lookup ages for a specific String. Take a look at java.util.Map and its implementations.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Joined: Jul 05, 2001
Originally posted by Jessica Sant: ... this looks an awful lot like a homework assignment ...
No it is not a homework assignment. [ May 07, 2002: Message edited by: Melinda Wilson ]
Joined: Jan 30, 2000
Part II has a lot of redundancy. It seems to reduce to
This could probably be accomplished as:
For part I, I'd probably list all the states in a file, and read the file into a Map of some sort which allowed me to look up the min age for a given state, without a bunch of if/else if clauses. The Properties class would be a simple way to do this. It's probably not worth the trouble for the code as it is now - but if you plan to add the remaining states, or if you need to have other state-dependant information, I'd try to put it in a separate file where it's easy to read and update if necessary.