Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Build It For The Real World A Database Workbook

Authors: Wilson, Susan, Hoferek, Mary J.

1st Edition

0073197599, 9780073197593

More Books

Students also viewed these Databases questions

Question

Which personal relationships influenced you the most?

Answered: 1 week ago

Question

What were your most important educational experiences?

Answered: 1 week ago