Best writers. Best papers. Let professionals take care of your academic papers

Order a similar paper and get 15% discount on your first order with us
Use the following coupon "FIRST15"
ORDER NOW

Application: Personal Address Book

Application: Personal Address Book

As previously stated, Java collections are data structures used to

contain sets of data. There are several types of collections in Java. In your Discussion, you explored the use of Arrays and ArrayLists. Another useful collection method is the Map interface. Maps associate a key with a value; for example, a map used as a phone book might associate a person’s name with a phone number. By searching for the person’s name in the map, you could find his/her phone number, but you would not be able to search for a person’s phone number to find his/her name. There are two basic kinds of maps: HashMap<key_type, value_type>, designed for fast access, and TreeMap<key_type, value_type>, designed to keep entries in order by key. A TreeMap requires that the keys have a properly defined equals method and implement the Comparable interface. Fortunately, strings satisfy both sets of requirements, and are often used as keys.

In this assignment, use a TreeMap to implement a personal address book. Use the person’s name as the key, and store information about the person as the value (in a Person object). Declare the following information in the Person class:

Application: Personal Address BookAs previously stated, Java collections are data structures used to contain sets of data.There are several types of collections in Java. In your Discussion, you explored the useofArrays and ArrayLists. Another useful collection method is theMapinterface. Mapsassociate akeywith avalue;for example, a map used as a phone book might associatea person’s name with a phone number. By searching for the person’s name in the map,you could find his/her phone number, but you would not be able to search for a person’sphone number to find his/her name. There are two basic kinds of maps:HashMap<key_type,value_type>, designed for fast access, andTreeMap<key_type,value_type>, designed to keep entries in order by key. ATreeMap requires that the keys have a properly definedequalsmethod and implementtheComparableinterface. Fortunately, strings satisfy both sets of requirements, andare often used as keys.In this assignment, use a TreeMap to implement a personal address book. Use theperson’s name as the key, and store information about the person as the value (in aPersonobject). Declare the following information in thePersonclass:String name;String address; // physical addressString email;// email addresslong phoneNumber;Add two additional fields to store other important contact information. For example,alternate phone numbers, websites, and notes.You must save the information from the address book in a file to preserve it betweenruns of the program. A text file allows the user to view the data in any text editor, butrequires substantial programming to read the file and turn it back into aTreeMapof
Background image of page 1
Personobjects.Any time you want to write out or read in objects, the easiest way to save theinformation is as an object or as objects, usingObjectOutputStreamandObjectInputStream. The advantage of object I/O is ease of use. The disadvantageis that the files can only be used by Java programs that declare the objects inexactlythe same way, with no added, deleted, or changed field declarations.Use object I/O in this assignment, writing and reading the entire address book as asingleTreeMapobject.Object I/O requires that all parts of the objects to be read and written must beserializable,meaning that they must be able to be converted into an information formthat can be easily stored (i.e., encoded as a byte stream). Strings, longs, and TreeMapsare serializable. Make yourPersonobjects serializable by implementingSerializable:class Person implements Serializable.By doing this, you can properly read and write within a personal address book file.Your program must first ask the user whether to create a new address book, or to readin a file containing an existing address book. If the user wants to create a new addressbook, your program must create an emptyTreeMap<String, Person>. If the userwants to access an existing address book, your program must find the file name usingthe same process as you used for the “Fill-In-The-Blank” story. This time, however,instead of using aBufferedReader, use the following code:FileInputStream fis = new FileInputStream(file_name);ObjectInputStream ois = new ObjectInputStream(fis);addressBook = (TreeMap<String, Person>) ois.readObject();
Background image of page 2
 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"