Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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, designed for fast access, and TreeMap, 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. 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)ois.readObject();
ois.close();

Note that addressBookis the name of your TreeMap.

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.

Java, Programming

  • Category:- Java
  • Reference No.:- M91989003
  • Price:- $50

Priced at Now at $50, Verified Solution

Have any Question?


Related Questions in Java

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

Assessment instructionsin this assessment you will complete

Assessment Instructions In this assessment, you will complete the programming of two Java class methods in a console application that registers students for courses in a term of study. The application is written using th ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Assignment - java program using array of objectsobjectives

Assignment - JAVA Program using array of objects Objectives - This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details - For this assignment, you are required to develop a Menu ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As