Question: ANSWER THIS JAVA BASED QUESTION, USING THE MOST SIMPLE WAY TO BETTER UNDERSTAND AND EXPLAIN EACH STEP: Question 4 Aggregation Relationship: A: Part 1 :
ANSWER THIS JAVA BASED QUESTION, USING THE MOST SIMPLE WAY TO BETTER UNDERSTAND AND EXPLAIN EACH STEP: Question
Aggregation Relationship:
A:
Part :
I. Create a class Address with the following private fields:
city
street
number
postalcode
II Add the following public methods for Address:
A constructor that initializes all fields based on its parameters.
Getter methods getCity getStreet etc. that return the values of the fields.
Setter methods setCity setStreet etc. that update the field values based on the parameters.
A display method that prints the full address on the screen.
III. Create a class Person with the following private fields:
name
surname
yearofbirth constant
address of type Address
IV Add the public methods for Person:
A constructor that initializes all fields based on its parameters.
Getter methods getName getSurname getYearOfBirth etc. to return the values of the fields.
Setter methods setName setSurname etc. to update the field values.
A getAge method that calculates and returns the person's age based on the yearofbirth.
Hint: Use Calendar.getInstancegetCalendarYEAR to get the current year.
An is method that returns true if the person is years old or older, and false otherwise.
A changeAddress method that updates the person's address with new values passed as parameters.
A display method that prints all the persons details on the screen, including their age and full
address.
Part :
V Create a class Student with the following private fields:
id constant
semester
average
persondata constant type Person from part
VI The class contains the following public methods:
A constructor that initializes all fields based on its parameters.
Getter methods that return the values of the class fields.
setSemester and setAverage methods that update the semester and average fields based on their
parameters.
getYear method that calculates and returns the corresponding year of study based on the semester.
checkAverage method that returns true if the average field is greater than the value passed as a
parameter, and false otherwise.
Display method that prints all the student's data on the screen.
B:
Imagine we're designing a simple game. We need to represent a player that can wield a weapon. Using
aggregation, complete the following tasks:
I. Create a Weapon class with the following:
a A private field name for the weapon's name.
b A constructor that initializes the name field.
c A getter method getName that returns the name of the weapon.
II Create a Player class with the following:
a A private field name for the player's name.
b A private field weapon of type Weapon representing the weapon the player is wielding.
c A constructor that initializes both the name and weapon fields.
d A getter method getName that returns the player's name.
e A getter method getWeaponName that returns the name of the weapon the player is
wielding.
III. Create a Main class that:
a Creates a Weapon object eg a "Sword"
b Creates a Player object and assigns the Weapon to them.
c Prints out the player's name and the name of the weapon they are wielding.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
