Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USE JAVA Implement this Question on your Computer. Put your codes with a snapshot of the output screen and please paste them. (a) Design a

USE JAVA

Implement this Question on your Computer. Put your codes with a snapshot of the output screen and please paste them.

(a) Design a class to model Person objects. A person has a name (first name, last name), address, phone number, and gender (M/F). The class should contain all the setters and getters of all data fields, and the toString method for displaying complete information about the person. You must use the this operator in your implementation.

The Person class must implement the Comparable interface so that person objects can be compared with each other.

public interface Comparable {

public int compareTo(Object o);

}

The compareTo method determines the order of this object with the specified object o, and returns a negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object o. Use the last name in the comparison.

(b) Add an AddressBook class that manages a collection of Person objects. An AddressBook object will allow the programmer to add, delete, or search for a Person object in the address book. Use an ArrayList to store the Person objects of the AddressBook.

add: Adds a new Person object to the address book.

delete: Deletes a specified Person object from the address book if it is found (same first and last names).

search: Searches for a specified Person object in the address book and returns this person if it is found. Compare the first name and last name to see if he/she is the required person.

(c) Use the above classes to implement a program to do the following:

1. Create three Person objects p1, p2, and p3. Input their data from the keyboard, then store the objects's data on the address book.

p1: Name: Inas Ahmed, Address: Saidon, Phone#: 719999, 'F'

p2: Name: Ali Ezzat, Address: Beirut, Phone#: 713333, 'M'

p3: Name: Rida Samer, Address: Tripoli, Phone#: 715555, 'F'

2. Display the number of objects currently in the AddressBook.

3. Use the compareTo method to compare the first and last persons in the address book, and display the result of comparison on screen

4. Input a new person from the keyboard (first name: Ali, Last name: Ahmed). Then search for him/her in the AddressBook, and display the result of searching on screen.

5. Try to delete a person with first name: Rida, Last name: Samer. Make sure to search for the person before trying to delete him/her. If the person is not present in the AddressBook, you must display a message "Not found in address book".

6. Use the toString method to display the data of the current persons in the AddressBook.

7. Count how many persons are living in Beirut. Display the result on screen.

(Use data encapsulation to hide the data fields and prevent the direct access to them.)

(d) Draw a simplified UML showing the relationships between all classes including the Main and Scanner classes.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

7. How might you go about testing these assumptions?

Answered: 1 week ago