183k views
5 votes
In Java, make a simple address book application. It should be able to store Name, Street, City, State, ZIP and phone number. You can make any type of interface you would like to, however a simple text interface is probably the easiest. The main features to to:

• Add an contact to the address book
• Delete a contact from the address book
• Update a contact from the address book
• Display the address book
Create an aspect that when the user updates a contact the previous data is written to a file. Also create an aspect that when the user deletes a contact the contact information is written to a file

User Thwiegan
by
7.8k points

1 Answer

3 votes

Final answer:

To create an address book application in Java, you can use object-oriented programming concepts to create Contact and AddressBook classes. Implement methods to add, delete, and update contacts, and use file output streams to write previous data and deleted contacts to files.

Step-by-step explanation:

In Java, you can create a simple address book application using object-oriented programming concepts. Here is an example of how you can implement it:

  1. Create a Contact class with the necessary fields such as name, street, city, state, ZIP, and phone number.
  2. Create an AddressBook class that stores contacts in an ArrayList or another suitable data structure.
  3. Implement methods in the AddressBook class to add, delete, and update contacts by interacting with the Contact objects.
  4. To add a contact, create a new Contact object and add it to the AddressBook collection.
  5. To delete a contact, find the contact in the collection based on the provided criteria and remove it.
  6. To update a contact, find the contact in the collection based on the provided criteria and modify its fields.
  7. For the aspect of writing previous data to a file when updating a contact, you can use a file output stream to create or append to a file and write the previous contact information to it before updating it with the new data.
  8. Similarly, for the aspect of writing contact information to a file when deleting a contact, use a file output stream to append the contact information to a file before deleting it from the address book.
  9. Finally, implement a method to display the address book by iterating over the contacts and printing their details.

By following these steps, you can create a simple address book application in Java that allows adding, deleting, updating contacts as well as writing previous data and deleted contact information to files.

User CSnerd
by
8.1k points