Question: *******************person.java************ public class Person { private String name; public Person() { name = No name yet.; } public Person(String initialName) { name = initialName; }

 *******************person.java************ public class Person { private String name; public Person() {name = "No name yet."; } public Person(String initialName) { name =

*******************person.java************

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 sameName(Person otherPerson) { return (this.name.equalsIgnoreCase(otherPerson.name)); }

// define toString method here // define equals method here

}

**********student.java************

public class Student // *** make Student inherit from Person class { private int studentNumber; public Student() // no arg constructor { // *** invoke the no-arg constructor of the base class (Person) // *** set the studentNumber to 0, indicating no number yet } public Student(String initialName, int initialStudentNumber) { // *** invoke the explicit constructor of the base class (Person), passing it initialName // *** set the studentNumber to initialStudentNumber }

public int getStudentNumber() { //*** return the student number return 0; } public void setStudentNumber(int newStudentNumber) { //*** set the studentNumber to newStudentNumber }

// add toString method here

// add equals method here

public static void main(String [] args) { /****** Test Driver for Student class **************************** Student s1 = new Student(); s1.setName("Hermes Paris"); // uses the setName of the Person class s1.setStudentNumber(987654); Student s2 = new Student("Zeus Monassus", 12345); System.out.println("Student s1 = " + s1); System.out.println("Student s2 = " + s2); //******************************************************************/ } }

2.4 Student Inherits Person Finish the definition of the Person and Student classes. The Person class needs a toString and equals method The Student class should inherit all members from the Person class, and define a studentNumber instance variable, as well as methods to get and set this variable. It also needs to override the toString and equals methods from the Person class with additional code for dealing with the studentNumber. There is no input in the test -- the main program should simply verify your classes are construted properly (so you can use them in the next problem) by printing. LAB ACTIVITY 2.4.1: Student Inherits Person 0/5 Downloadable files Person.java Student.java Main.java package.bluej Download File is marked as read only Current file: Main.java 1 import java.util.Scanner; 2 3 public class Main 4 { 5 public static void main(String [] args) 6 { 7 //****** Test Driver for Student class ********* 8 Student s1 = new Studento; 9 10 s1.setName("Hermes Paris"); // uses the setName of the Person class 11 s1.setStudentNumber(987654); 12 13 Student s2 = new Student("Zeus Monassus", 12345); 14 15 System.out.println("Student s1 - " + s1); 16 System.out.println("Student s2 = + s2); 17 18 //*********** *************/ 19 20 21 } 22 23 }

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!