Implement a personal address book

Assignment Help JAVA Programming
Reference no: EM131233113

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 equalsmethod and implement the Comparableinterface. 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 Personobject). Declare the following information in the Personclass:

String name;
String address; // physical address
String email; // email address
longphoneNumber;

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 between runs of the program. A text file allows the user to view the data in any text editor, but requires substantial programming to read the file and turn it back into a TreeMapof Personobjects.

Any time you want to write out or read in objects, the easiest way to save the information is as an object or as objects, using ObjectOutputStreamand ObjectInputStream. The advantage of object I/O is ease of use. The disadvantage is that the files can only be used by Java programs that declare the objects in exactly the 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 a single TreeMapobject.

Object I/O requires that all parts of the objects to be read and written must be serializable, meaning that they must be able to be converted into an information form that can be easily stored (i.e., encoded as a byte stream). Strings, longs, and TreeMaps are serializable. Make your Personobjects serializable by implementing
Serializable:

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 read in a file containing an existing address book. If the user wants to create a new address book, your program must create an empty TreeMap<String, Person>. If the user wants to access an existing address book, your program must find the file name using the same process as you used for the "Fill-In-The-Blank" story. This time, however, instead of using a BufferedReader, use the following code:

FileInputStreamfis = new FileInputStream(file_name);
ObjectInputStreamois = new ObjectInputStream(fis);

addressBook = (TreeMap<String, Person>)ois.readObject();
ois.close();

Note that addressBookis the name of your TreeMap<String, Person>.

Once you have a (possibly new and empty) address book, your program should allow the user to do the following things:

- Get Help on how to use the program. As soon as an address book is loaded, print out a concise but complete list of the commands a user can enter. One of them should be a "help" command to print out the list again. The list must be detailed enough to explain the features to a user who is unfamiliar with your program.

- Add an entry to the address book. Do not allow an empty string for the person's name. All other fields are optional for the user to complete. For fields that the user leaves blank, store the empty string (for Stringfields), or the number 0 (for longorintfields).

- Look up an entry. When the user enters a person's name, display all of the information about that person.

- Edit an entry. Allow the user to change information about a person.

- Delete an entry. Allow the user to delete the entry from the map.

- Save the address book. If the address book is new, use JFileChooser.showSaveDialogto specify where to save the file; otherwise save it back to the same file that was read in. Use the following code to save an object file:

FileOutputStreamfos = new FileOutputStream(file_name);
ObjectOutputStreamoos = new ObjectOutputStream(fos);
oos.writeObject(addressBook);
oos.close();

The user will interact with your program using a text interface (that is, Scanner, and System.out.println). The details of this interaction are up to you, but you must provide all of the necessary details of your program's features in your program's "help" command. Also remember to write methods to handle input and output that are separate from the methods that do calculations.

File input and output can be complicated. It is important to test your input and output to make sure that your address book contains the correct information. Do this by creating an address book with several entries and then ending your program. Then, run your program again and open the address book to verify the entries.

By now you should be quite comfortable with the TDD approach, and you should be using it for all the methods that manipulate (add, look up, edit, delete) your address book, but not for methods that handle file I/O or that communicate with the user.

Include screenshots of your program running as part of your submission. Include screenshots of creating an address book, adding several entries, looking up two valid entries and two invalid entries, and using the "help" command. Run your program again and show screenshots of opening the address book from the previous run and looking up two valid entries and two invalid entries. Show screenshots of your program being tested with JUnit.

Save your NetBeans Project and screen shots of the working program as a ".zip" file.

Reference no: EM131233113

Questions Cloud

Difference between simplifying and critical assumption : What is the difference between simplifying and critical assumption? Can u give me some example?
Analyze the future of criminal justice policy : Describe your thesis regarding the future of criminal justice policy making. -  Analyze the future of criminal justice policy.
Classical aggregate demand curve : If the propensity to hold money is 6 and the money supply is 12, then the classical aggregate demand curve is
Write vision statement reflecting the new mission statement : Write a mission statement that reflects this new direction for St. Mary's. Write a vision statement reflecting the new mission statement. What type of strategy did the leadership team at St. Mary's pursue?
Implement a personal address book : How to use the program. As soon as an address book is loaded, print out a concise but complete list of the commands a user can enter. One of them should be a "help" command to print out the list again.
Analysis of possible ways to improve resilience and protect : Analysis of possible ways to improve resilience and protect the infrastructure: what alternatives have been suggested, and by whom? What are the pros and cons of each - be sure to examine costs and feasibility.
Is the agent independently liable on contract : Does it matter whether the principal does not know what the agent knows? If the agent makes a contract, is the principal always bound by it? Is the agent independently liable on a contract if the principal does not honor it?
Identifying comparative advantage : In your answer be sure to be very specific as to how you identified the comparative advantage in each country and define how one goes about identifying comparative advantage.
Identify at least two professional skills : Identify at least two professional skills that will be needed to strengthen in order to be successful in your career field.

Reviews

inf1233113

10/8/2016 7:59:38 AM

Amazing, the program is working fine, there is no error at all. you guys are awesome, thanks a lot. i will need more help my next assignments. i'm new to this part so i will be requiring help of your experts. really good thanks a ton.

len1233113

10/7/2016 2:03:58 AM

Include screenshots of your program running as part of your submission. Include screenshots of creating an address book, adding several entries, looking up two valid entries and two invalid entries, and using the "help" command. Run your program again and show screenshots of opening the address book from the previous run and looking up two valid entries and two invalid entries. Show screenshots of your program being tested with JUnit. Save your NetBeans Project and screen shots of the working program as a ".zip" file. Thanks.

Write a Review

JAVA Programming Questions & Answers

  Define two different physical representations for strings

Define an ADT for character strings. Your ADT should consist of typical functions that can be performed on strings, with each function defined in terms of its input and output. Then define two different physical representations for strings.

  Procedural programming and object-oriented programming

What are the similarities between procedural programming and object-oriented programming? What are the differences between procedural programming and object-oriented programming

  Eliminate the last comma in the string output

Eliminate the last comma in the String Output which includes array output values from "hourlyTemp[i]" (entire list). My guess is that this needs to incorporate "%d" somehow but my online book won't accept the use of "%d" for some reason. From the boo..

  Create a method that would search through an arraylist

What is the best way of the following ways (For each, Iterator, While with index) that you would use to create a method that would search through an ArrayList of files for a certain file and then delete it, and why?

  Communicating parties can encrypt

In an RSA cryptosystem, a public key infrastructure is implemented such that the communicating parties can encrypt, and be able to decrypt the ciphertext. Given p = 3 and q = 11 encrypt a message m =2, then decrypt the same message if the private ..

  Technical community blog

Write a blog article for a coding and technical community blog.

  Write a version of sumpairs

Write a version of sumPairs  that sums each component of the pairs separately, returning a pair consisting of the sum of the first components and the sum of the second components. So basically [(3,1)(10,3)] would return (13,4).

  Program that computes the annual road tax

All cars registered on or before 1 March 2001 are charged according to their engine size (in cc). A car with an engine size of less than or equal to 1550cc is charged at 110 GBP; otherwise it is charged at 165 GBP.

  Design an adt for a two-color

Design an ADT for a two-color, double-stack ADT that consists of two stacks one "red" and one "blue" and has as its operations color-coded versions of the regular stack ADT operations.

  Write an interactive program to maintain the space city

Write an interactive program, in Java, to aid in monitoring and maintaining all aspects of Tasks, Crew and Ship's, that is, maintaining the Space City.

  Company infrastructure and the identification

Your CEO meets with you and assigns you the following tasks, to be assembled in a written report to the CEO:  The review of the company's infrastructure and the identification of all types of vulnerabilities -- environmental, physical, an..

  Which statement is true about a non-static inner class

Which statement is true about a non-static inner class? Clicking the closing button on the upper-right corner of a frame generates a(n) _____ event.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd