As a relative newbie to Java, I'd like to practice creating an simple application where a phone number is entered as input by the user and a corresponding address is returned. What should my approach be? Do I have to use a separate file for to contain the addresses? Or can I set up an array list or vector instead and add each address "on the fly"? Any tips on the GUI and listeners involved? My most important requirement is that the list of addresses doesn't get erased each time I turn off the computer (I think the term is Serializable?)
Joined: Nov 06, 2000
Your addresses can also be in a datbase. You can use the phone number as the key to lookup an address. If it's web based, you can have your client enter the phone number through JSP/HTML and then have a servlet in the backend that does the Db lookup and returns the result to the JSP to display. OTOH, you can just have the servlet display the results directly (the servlet will format and output HTML)
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Joined: Sep 29, 2000
I would start out by putting the address information (hardcoded) in a Vector or better yet an ArrayList as a set of Address objects. Once you have the mechanism of retrieving the information from the ArrayList and displaying it you can go back and add in the GUI input or I/O neccessary to read the data in from a source and loading the ArrayList.
"JavaRanch, where the deer and the Certified play" - David O'Meara
Joined: May 17, 2001
Look into HashMap you can use the phone number as the key to retrieve your adress object. That way you don't need to write your own lookup stategy if you don't use a DB.