Question: So I'm using inheritance to write a program and I need help for the first part of it. The output is suppose to look like

So I'm using inheritance to write a program and I need help for the first part of it. The output is suppose to look like this:

Peter Luong

----------------------------------------

Home Address:10 FakeHome Street

Staged City, NA 22222

Phone Number: 858-789-8575

Email Address:fake0@foo.edu

ID:1

I have 4 classes Person, Name, Address, along with Main. Name and Address cannot be changed and the variables for Person cannot be changed (It will be used later as a super class). I'm not sure how to acquire and display the information. This is my unfinished Person code and other classes below.

class Main {

public static void main(String[] args) {

Person [] vPersons = new Person [5];

Person p1 = new Person("Peter", null,"Luong", home1, "858-789-8575", "fake0@foo.edu");

}

}

public class Address {

private String streetAddress;

private String city;

private String state;

private long zipCode;

// Sets up this Address object with the specified data.

public Address (String streetAddress, String city, String state, long zipCode)

{

this.streetAddress = streetAddress;

this.city = city;

this.state = state;

this.zipCode = zipCode;

}

// Returns this Address object as a string.

public String toString()

{

String result;

result = streetAddress + " ";

result += city + ", " + state + " " + zipCode;

return result;

}

}

public class Name {

private String firstName;

private String middleName;

private String lastName;

//constructor

public Name (String firstName, String middleName, String lastName)

{

this.firstName =firstName;

this.middleName = middleName;

this.lastName = lastName;

}

//constructor

public Name (String firstName, String lastName)

{

this.firstName =firstName;

this.middleName = middleName;

this.lastName = lastName;

}

//prints information

public String toString()

{ if (this.middleName == null)

return this.firstName +" " + this.lastName;

else

return this.firstName +" " +this.middleName+" " +this.lastName;

}

}

class Person{

private int id=0;

private Name name;

private Address homeAddress;

private String phoneNumber;

private String email;

private static int recordNumber =0;

protected Person(String first, String middle, String last, Address homeAddress, String phoneNumber, String email){

this.homeAddress = homeAddress;

this.phoneNumber = phoneNumber;

this.email = email;

}

public String getName(){

return name;

}

public String toString(){

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!