Question: For the attached JAVA programs: Add a private variable SSN to the person class. Add a private variable major to the student class. Modify the

For the attached JAVA programs:

Add a private variable SSN to the person class.

Add a private variable major to the student class.

Modify the InheritanceDemo to read the name, student Number, SSN, and the major.

Upload the the three modified files. You have to add the comments and explanations for the modified files.

public class Person { private String name; public Person( ) { name = "No name yet"; } public Person(String initialName) { name = initialName; } public void setName(String newName) { name = newName; } public String getName( ) { return name; } public void writeOutput( ) { System.out.println("Name: " + name); } public boolean hasSameName(Person otherPerson) { return this.name.equalsIgnoreCase(otherPerson.name); } }

public class Student extends Person { private int studentNumber; public Student( ) { super( ); studentNumber = 0;//Indicating no number yet } public Student(String initialName, int initialStudentNumber) { super(initialName); studentNumber = initialStudentNumber; } public void reset(String newName, int newStudentNumber) { setName(newName); studentNumber = newStudentNumber; } public int getStudentNumber( ) { return studentNumber; } public void setStudentNumber(int newStudentNumber) { studentNumber = newStudentNumber; } public void writeOutput( ) { System.out.println("Name: " + getName( )); System.out.println("Student Number: " + studentNumber); } public boolean equals(Student otherStudent) { return this.hasSameName(otherStudent) && (this.studentNumber == otherStudent.studentNumber); } public String toString( ) { return "Name: " + getName( ) + " Student number: " + studentNumber; } /* //For Optional Section public boolean equals(Object otherObject) { if (otherObject == null) return false; else if (!(otherObject instanceof Student)) return false;

else { Student otherStudent = (Student)otherObject; return (this.sameName(otherStudent) && (this.studentNumber == otherStudent.studentNumber)); } } */ }

public class InheritanceDemo { public static void main(String[] args) { Student s = new Student( ); s.setName("Warren Peace"); s.setStudentNumber(1234); s.writeOutput( ); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!