Question: In Java with comments throughout: Create a class called PersonAddress that includes fields for street Address, City, State, and zipcode. Add a private data item
In Java with comments throughout:
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)
public class Person { private String lastName; private String 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; } }
Instantiate an object using the OlympicAthlete class and pass in all data using the constructor including the address data. Display all data.
public class OlympicAthlete { //Variable for first name public String firstName; //Variable for last name public String lastName; //Variable for age public int age; //Variable for number of medals public int numberOfMedals; //OlympicAthlete constructor initialize data members with the values passed. public OlympicAthlete(String firstName, String lastName, int age, int numberOfMedals) { this.firstName = firstName; this.lastName = lastName; this.age = age; this.numberOfMedals = numberOfMedals;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
