Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA ONLY THANK YOU! The class below describes a Person. In the next questions, you will write a class called Instructor. An Instructor has an

JAVA ONLY THANK YOU!

The class below describes a Person. In the next questions, you will write a class called Instructor. An Instructor has an additional String variable that describes the subject that they teach.

(These classes might be used in a Human Resources software system at a university.)

For full credit, follow good principles of class design, encapsulation, and inheritance.

I recommend writing the class in your development environment to make sure it compiles and then copying the code into the appropriate question

public class Person {

private String name;

private final static String DEFAULT_NAME = "N/A"; public Person() {

this(DEFAULT_NAME);

} public Person(String name) {

this.name = name;

}public void setName(String name) {

this.name = name;

}public String getName() {

return name;

} public String toString() {

return Name: + name;

} public boolean equals(Object obj) {

if(obj instanceof Person) {

Person otherPerson = (Person) obj;

return name.equalsIgnoreCase(otherPerson.getName());

} else {

return false;

}

} }

Write the class header and the instance data variables for the Instructor class.

An Instructor is a person that is further described by a subject that they teach.

Write two constructors for the Instructor class:

a default constructor that takes no parameters

a constructor that takes in both the name and subject as parameters

Write accessor and mutator (getter and setter) methods. Include validity checking where appropriate.

Write a toString method to return a text representation of the Instructor that includes both the name and subject taught. The format should be a multi-line representation with the name on the first line and the subject on the second.

Write an equals method for the Instructor class. Two Instructor objects are considered the same (logically equivalent) if they have the same name and subject.

Write code that would go inside a driver program with a main method.

Create an array to hold 5 Person objects

Fill the array with some Person and some Instructor objects

Iterate the array and print a text representation of each object

Iterate the array and count how many instructors teach Math

Use polymorphism to do this!

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

More Books

Students also viewed these Databases questions

Question

How the corporate governance effect to institutional differences?

Answered: 1 week ago