Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

*In Java I want you to use Inheritance and Composition in this program. You DO N

ID: 2247198 • Letter: #

Question

*In Java

I want you to use Inheritance and Composition in this program. You DO NOT have to include Exception Handling.

Your assignment is to design an online address book that contains the functionality described below. I want you to be able to process 10 entries and implement a menu system to perform the required program operations, this will be created in the ADT AddressBook, but the classes Address, Date, Person, ExtPerson should be created first.

("Welcome to the address book program.");

        ("Choose among the following options:");

        ("1: To see if a person is in the address book");

        ("2: Print the information of a person");

        ("3: Print the names of person having birthday in a particular month");

        ("4: Print the names of persons having a particular status");

        ("5: Print the address book");

        ("9: Terminate the program");

I want you to make ALL of the data members in each class PRIVATE. I will specifically be looking for your use of constructors to initialize the data members. Remember that the keyword super must be used to call a base class constructors and/or methods from a derived class.

In addition to the implementing class (which will create an object of type AddressBook), you will be creating the following classes.

Address -street number, city, state, zip

ExtPerson (derived from Person AND is composite)- char status, Address address

Person-String name, int age, Date date of birth

Date-month, day, year

AddressBook (composite class)-main method, array of Person

Testing:

Make sure you are testing every method you wrote.

Deliverables:

1.Your source code from ALL the classes you create and/or use. I also want a UML diagram for EVERY class (which can be used to design your solution).

2.Screen prints of your test scenarios.
3.Include comments

ex of class Address

public class Address {

private int streetNumber;

private String city;

private String state;

private int zip;

/**

*no arg constructor

*/

Address(){

}

/**

* @param streetnumber

* @param city

* @param state

* @param zip

*/

Address(int streetnumber, String city, String state, int zip) {

this.setStreetNumber(streetnumber);

this.setCity(city);

this.setState(state);

this.setZip(zip);

}

/**

*

* @return the streetNumber

*/

public int getStreetNumber() {

return streetNumber;

}

/**

* @param streetNumber the streetNumber to set

*/

public void setStreetNumber(int streetNumber) {

this.streetNumber = streetNumber;

}

/**

* @return the city

*/

public String getCity() {

return city;

}

/**

* @param city the city to set

*/

public void setCity(String city) {

this.city = city;

}

/**

* @return the state

*/

public String getState() {

return state;

}

/**

* @param state the state to set

*/

public void setState(String state) {

this.state = state;

}

/**

* @return the zip

*/

public int getZip() {

return zip;

}

/**

* @param zip the zip to set

*/

public void setZip(int zip) {

this.zip = zip;

}

/* (non-Javadoc)

* @see java.lang.Object#toString()

*/

@Override

public String toString() {

return "Address [streetNumber=" + streetNumber + ", city=" + city + ", state=" + state + ", zip=" + zip + "]";

}

}

Explanation / Answer

package address_book;

public class Person {

private String name;

private int age;

Date date;

public Person()

{

}

public Person(String name, int age, Date date) {

this.name = name;

this.age = age;

this.date = date;

}

public String getName() {

return name;

}

public int getAge() {

return age;

}

public Date getDate() {

return date;

}

public void setName(String name) {

this.name = name;

}

public void setAge(int age) {

this.age = age;

}

public void setDate(Date date) {

this.date = date;

}

public boolean equals(Person other)

{

boolean isEqual = true;

if(!(other.name.equals(this.name)))

isEqual = false;

if(!(other.age == this.age))

isEqual = false;

if(!(other.date.equals(date)))

isEqual = false;

return isEqual;

}

public String toString()

{

return "Name: " + this.name+ " " +

"Age: " + this.age + " " +

"Date: " + this.date;

}

}

package address_book;

public class Date {

private int day;

private int month;

private int year;

public Date()

{

day = 1;

month = 1;

year = 1990;

}

public Date(int day, int month, int year) {

this.day = day;

this.month = month;

this.year = year;

}

public int getDay() {

return day;

}

public int getMonth() {

return month;

}

public int getYear() {

return year;

}

public void setDay(int day) {

this.day = day;

}

public void setMonth(int month) {

this.month = month;

}

public void setYear(int year) {

this.year = year;

}

public boolean equals(Date other)

{

boolean isEqual = true;

if(!(other.day == this.day))

isEqual = false;

if(!(other.month == this.month))

isEqual = false;

if(!(other.year == this.year))

isEqual = false;

return isEqual;

}

public String toString()

{

String day, month;

if(this.day < 10)

day = "0"+this.day;

else

day = ""+ this.day;

if(this.month < 10)

month = "0" + this.month;

else

month = "" + this.month;

return month + " / " + day + " / " + year;

}

}

package address_book;

import java.util.ArrayList;

import java.util.List;

public class ExtPerson extends Person {

private char status;

private Address address;

public ExtPerson() {

super();

// TODO Auto-generated constructor stub

this.status = 'S';

}

public ExtPerson(String name, int age, Date date, char status, Address address) {

super(name, age, date);

// TODO Auto-generated constructor stub

this.status = status;

this.address = address;

}

public char getStatus() {

return status;

}

public Address getAddress() {

return address;

}

public void setStatus(char status) {

this.status = status;

}

public void setAddress(Address address) {

this.address = address;

}

public String toString()

{

return "Name: "+super.getName()+" "+

"Age: " + super.getAge()+" "+

"Status: " + getStatus() +" "+

"DOB: " + super.getDate()+" "+

getAddress()+" ";

}

}

package address_book;

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class AddressBook {

// List to store the Persons

static List<ExtPerson> person = new ArrayList<ExtPerson>();

public static void main(String args[])

{

int choice;

System.out.println("Welcome to the address book program. ");

AddDefaultPersons();

while(true)

{

choice = printMenu();

if(choice < 1)

{

System.out.println("Invalid choice! ");

System.out.println();

}

else if(choice > 5 && choice < 9)

{

System.out.println("Invalid choice!");

System.out.println();

}

else if(choice > 9)

{

System.out.println("Invalid choice!");

System.out.println();

}

else

{

if(choice == 1)

{

searchPerson();

}

else if(choice == 2)

{

printPerson();

}

else if(choice == 3)

{

printPersonBasedOnBday();

}

else if(choice == 4)

{

printBasedOnStatus();

}

else if(choice == 5)

{

printAddressBook();

}

else if(choice == 9)

{

System.out.println("Thank you for using the address boook. Have a nice day!");

break;

}

}

}

}

/**

* Method to print menu

* @return

*/

public static int printMenu()

{

Scanner input = new Scanner(System.in);

int choice = 0;

while(true)

{

System.out.println("Choose among the following options:");

System.out.println("1: To see if a person is in the address book");

System.out.println("2: Print the information of a person");

System.out.println("3: Print the names of person having birthday in a particular month");

System.out.println("4: Print the names of persons having a particular status");

System.out.println("5: Print the address book");

System.out.println("9: Terminate the program");

System.out.print("Enter your choice: ");

try

{

choice = Integer.parseInt(input.nextLine());

break;

}

catch(NumberFormatException ex)

{

System.out.println(" Invalid Input! Please provide a valid integer input. ");

}

}

return choice;

}

/**

* Method to add default persons at start of the program

* By default 4 persons has been added in the list

*/

public static void AddDefaultPersons()

{

ExtPerson person1 = new ExtPerson();

person1.setAddress(new Address(101, "Mulund", "Maharashtra", 123456));

person1.setAge(23);

person1.setDate(new Date(1, 10, 1994));

person1.setStatus('S');

person1.setName("Peter");

person.add(person1);

ExtPerson person2 = new ExtPerson();

person2.setAddress(new Address(2354, "Howrah", "Kolkata", 134256));

person2.setAge(27);

person2.setDate(new Date(3, 10, 1990));

person2.setStatus('M');

person2.setName("Kumar");

person.add(person2);

ExtPerson person3 = new ExtPerson();

person3.setAddress(new Address(503, "Hyderabad", "Telangana", 324543));

person3.setAge(23);

person3.setDate(new Date(4, 4, 1994));

person3.setStatus('M');

person3.setName("Robert");

person.add(person3);

ExtPerson person4 = new ExtPerson();

person4.setAddress(new Address(504, "Hyderabad", "Telangana", 324543));

person4.setAge(31);

person4.setDate(new Date(10, 4, 1985));

person4.setStatus('S');

person4.setName("John");

person.add(person4);

// You can add more persons like above

}

/**

* method to verify whether a person exist in the list or not

*/

public static void searchPerson()

{

String name;

System.out.print("Enter the name of the person you want to verify in the list: ");

Scanner input = new Scanner(System.in);

name = input.nextLine();

int count = 0;

for(int i = 0; i < person.size(); i++)

{

if(person.get(i).getName().equalsIgnoreCase(name))

{

count++;

}

}

if(count > 0)

{

System.out.println(" There is/are total " + count + " person(s) with that name in the list");

}

else

System.out.println(" There is no person with that name in the list.");

System.out.println();

}

/**

* Method to print a person details based on his input name

*/

public static void printPerson()

{

String name;

Scanner input = new Scanner(System.in);

System.out.print("Enter the name of the person you want to look: ");

name = input.nextLine();

System.out.println();

int flag = 0;

int count = 1;

for(int i = 0; i < person.size(); i++)

{

if(person.get(i).getName().equalsIgnoreCase(name))

{

flag = 1;

System.out.println("Found #" + (count) );

System.out.println();

System.out.println(person.get(i));

count++;

}

}

if(flag == 0)

System.out.println("There is no person in that list with that name.");

}

/**

* Method to print detail of a person based on his b'day

*/

public static void printPersonBasedOnBday()

{

int m = 0;

Scanner input = new Scanner(System.in);

System.out.print("Enter the person's month of the birth: ");

m = Integer.parseInt(input.nextLine());

int flag = 0;

int count = 1;

for(int i = 0; i < person.size(); i++)

{

if(person.get(i).getDate().getMonth() == m)

{

flag = 1;

System.out.println("Found #" + (count) );

System.out.println();

System.out.println(person.get(i).getName());

count++;

}

}

if(flag == 0)

System.out.println("There is no person in that list with that b'day.");

}

/**

* Method to print the detail of person based on input relationship status

*/

public static void printBasedOnStatus()

{

char status;

Scanner input = new Scanner(System.in);

System.out.print("Enter the relationship status of the person: ");

status = input.nextLine().charAt(0);

int flag = 0;

int count = 1;

for(int i = 0; i < person.size(); i++)

{

if(person.get(i).getStatus() == status)

{

flag = 1;

System.out.println("Found #" + (count) );

System.out.println();

System.out.println(person.get(i));

count++;

}

}

if(flag == 0)

{

System.out.println("No person found with that relationship status");

}

}

/**

* main method

*/

public static void printAddressBook()

{

for(int i = 0; i<person.size(); i++)

{

System.out.println("Person #" + (i+1));

System.out.println("------------------");

System.out.println(person.get(i));

}

}

}

Welcome to the address book program.

Choose among the following options:
1: To see if a person is in the address book
2: Print the information of a person
3: Print the names of person having birthday in a particular month
4: Print the names of persons having a particular status
5: Print the address book
9: Terminate the program
Enter your choice: 10
Invalid choice!

Choose among the following options:
1: To see if a person is in the address book
2: Print the information of a person
3: Print the names of person having birthday in a particular month
4: Print the names of persons having a particular status
5: Print the address book
9: Terminate the program
Enter your choice: 6
Invalid choice!

Choose among the following options:
1: To see if a person is in the address book
2: Print the information of a person
3: Print the names of person having birthday in a particular month
4: Print the names of persons having a particular status
5: Print the address book
9: Terminate the program
Enter your choice: -1
Invalid choice!

Choose among the following options:
1: To see if a person is in the address book
2: Print the information of a person
3: Print the names of person having birthday in a particular month
4: Print the names of persons having a particular status
5: Print the address book
9: Terminate the program
Enter your choice: sd

Invalid Input!
Please provide a valid integer input.

Choose among the following options:
1: To see if a person is in the address book
2: Print the information of a person
3: Print the names of person having birthday in a particular month
4: Print the names of persons having a particular status
5: Print the address book
9: Terminate the program
Enter your choice: 5
Person #1
------------------
Name: Peter
Age: 23
Status: S
DOB: 10 / 01 / 1994
Address::
Street Number: 101
City: Mulund, State: Maharashtra
Zip: 123456

Person #2
------------------
Name: Kumar
Age: 27
Status: M
DOB: 10 / 03 / 1990
Address::
Street Number: 2354
City: Howrah, State: Kolkata
Zip: 134256

Person #3
------------------
Name: Robert
Age: 23
Status: M
DOB: 04 / 04 / 1994
Address::
Street Number: 503
City: Hyderabad, State: Telangana
Zip: 324543

Person #4
------------------
Name: John
Age: 31
Status: S
DOB: 04 / 10 / 1985
Address::
Street Number: 504
City: Hyderabad, State: Telangana
Zip: 324543

Choose among the following options:
1: To see if a person is in the address book
2: Print the information of a person
3: Print the names of person having birthday in a particular month
4: Print the names of persons having a particular status
5: Print the address book
9: Terminate the program
Enter your choice: 1
Enter the name of the person you want to verify in the list: peter

There is/are total 1 person(s) with that name in the list

Choose among the following options:
1: To see if a person is in the address book
2: Print the information of a person
3: Print the names of person having birthday in a particular month
4: Print the names of persons having a particular status
5: Print the address book
9: Terminate the program
Enter your choice: 2
Enter the name of the person you want to look: john

Found #1

Name: John
Age: 31
Status: S
DOB: 04 / 10 / 1985
Address::
Street Number: 504
City: Hyderabad, State: Telangana
Zip: 324543

Choose among the following options:
1: To see if a person is in the address book
2: Print the information of a person
3: Print the names of person having birthday in a particular month
4: Print the names of persons having a particular status
5: Print the address book
9: Terminate the program
Enter your choice: 3
Enter the person's month of the birth: 4
Found #1

Robert
Found #2

John
Choose among the following options:
1: To see if a person is in the address book
2: Print the information of a person
3: Print the names of person having birthday in a particular month
4: Print the names of persons having a particular status
5: Print the address book
9: Terminate the program
Enter your choice: 4
Enter the relationship status of the person: S
Found #1

Name: Peter
Age: 23
Status: S
DOB: 10 / 01 / 1994
Address::
Street Number: 101
City: Mulund, State: Maharashtra
Zip: 123456

Found #2

Name: John
Age: 31
Status: S
DOB: 04 / 10 / 1985
Address::
Street Number: 504
City: Hyderabad, State: Telangana
Zip: 324543

Choose among the following options:
1: To see if a person is in the address book
2: Print the information of a person
3: Print the names of person having birthday in a particular month
4: Print the names of persons having a particular status
5: Print the address book
9: Terminate the program
Enter your choice: 9
Thank you for using the address boook.
Have a nice day!

Instructions: Open your java ide create a new java project with package name address_book and within this package create the above-posted classes and copy their contents into it and run the driver file AddressBook.java. Please ensure that you run the driver file i.e., AddressBook.java running any other file would not work and will return an error.

File Address.java package address_book;
public class Address {
private int streetNumber;
private String city;
private String state;
private int zip;
/**
*no arg constructor
*/
Address()
{
}
/**
* @param streetnumber
* @param city
* @param state
* @param zip
*/
Address(int streetnumber, String city, String state, int zip) {
this.setStreetNumber(streetnumber);
this.setCity(city);
this.setState(state);
this.setZip(zip);
}
/**
*
* @return the streetNumber
*/
public int getStreetNumber() {
return streetNumber;
}
/**
* @param streetNumber the streetNumber to set
*/
public void setStreetNumber(int streetNumber) {
this.streetNumber = streetNumber;
}
/**
* @return the city
*/
public String getCity() {
return city;
}
/**
* @param city the city to set
*/
public void setCity(String city) {
this.city = city;
}
/**
* @return the state
*/
public String getState() {
return state;
}
/**
* @param state the state to set
*/
public void setState(String state) {
this.state = state;
}
/**
* @return the zip
*/
public int getZip() {
return zip;
}
/**
* @param zip the zip to set
*/
public void setZip(int zip) {
this.zip = zip;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Address:: Street Number: " + streetNumber + " City: " + city + ", State: " + state + " Zip: " + zip ;
}
}