Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

Students also viewed these Databases questions

Question

Write a Python program to check an input number is prime or not.

Answered: 1 week ago

Question

Write a program to check an input year is leap or not.

Answered: 1 week ago