Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You must create a file called Student.java. This class will define a Student object which is the same as a Person object (as defined for

You must create a file called Student.java. This class will define a Student object which is the same as a Person object (as defined for problem 1 above), but with the addition of an gpa attribute. The Student class must NOT use inheritance to reuse the functionality from Person. Instead you must include a reference to a Person object as one of the attributes of Student (so that Student contains a Person object inside itself, this is what we mean by composition). The internal Person object will take care of the name and the phone number for the Student, and the Student will specifically take care of the gpa attribute. The Student class must not allow subclassing, nor changes to any attribute data. Calls to Student to get the name or phone number for the Student should be passed through to the internal Person objects methods, which will return the data to Student who then returns it to the code that called the method in Student. You are being given a file called UseStudent.java which contains a main() method you should use to test that your composed class design is working correctly.

Here is person class:

public class Person { String name; String phone;

public Person() { name = new String(); phone = new String(); }

public Person(String name, String phone) { this.name = name; this.phone = phone; }

public void setName(String name) { this.name = name; }

public void setPhone(String phone) { this.phone = phone; }

public String getName() { return name; }

public String getPhone() { return phone; }

}

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

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions

Question

Compare levels of resolution in conflict outcomes?

Answered: 1 week ago

Question

Strategies for Managing Conflict Conflict Outcomes?

Answered: 1 week ago