Question: write in java with comments please. i need to add on to this program. 2. Create a class called PersonAddress that includes fields for street

write in java with comments please. i need to add on to this program.

2. Create a class called PersonAddress that includes fields for street Address, City, State, and zipcode. Add a private data item to the Person class (defined above) that is of type PersonAddress as well as get methods to retrieve data from this object. (This is an example of aggregation). Instantiate an object using the OlympicAthlete class and pass in all data using the constructor including the address data. Display all data.

3. Create an ArrayList that holds OlympicAthlete objects. Add three objects to the array list. Display the info about each athlete that is in the array list

abstract class Person {

private String lastName, firstName;

private int age;

public Person(String lastName, String firstName, int age) {

this.lastName = lastName;

this.firstName = firstName;

this.age = age;

}

public String getLastName() {

return lastName;

}

public String getFirstName() {

return firstName;

}

public int getAge() {

return age;

}

abstract void display();

}

class OlympicAthlete extends Person {

private int numberOfGoldMedals;

public OlympicAthlete(String lastName, String firstName, int age, int numberOfGoldMedals) {

super(lastName, firstName, age);

this.numberOfGoldMedals = numberOfGoldMedals;

}

public int getNumberOfGoldMedals() {

return numberOfGoldMedals;

}

@Override

void display() {

System.out.println("Name: " + (getFirstName() + " " + getLastName()));

System.out.println("Age: " + getAge());

System.out.println("Number of gold medals: " + numberOfGoldMedals);

}

}

public class Main {

public static void main(String[] args) {

OlympicAthlete olympicAthlete = new OlympicAthlete("John", "Doe", 32, 4);

olympicAthlete.display();

}

}

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!