The following figure shows a UML diagram in which the class
The following figure shows a UML diagram in which the class Student is inherited from the class Person. Implement the two classes. Write a demo program that tests all the methods in the Student class as well as the inherited methods. Note: In the toString method in the Student class, use the method getName() to get the name.
*I am using JGrasp so please make sure it is compatible
*Please comment throughout code
Exercise 3: The following figure shows a UML diagram in which the class student is inherited from the class Person Person name: String Person setName (String newName) void getName String toString String has SameName (Person another Person) boolean Student student Number: int Student reset (String newName int newNumber) void get StudentNumber int setstudent Number (int n) void tostring String equals (Student another Stuent) booleanSolution
StudentDemo.java
 public class StudentDemo {
  
    public static void main(String[] args) {
        Student s = new Student();
        s.reset(\"Suresh\",100);
        System.out.println(s);
        Student s1 = new Student();
        s1.reset(\"Ssekhar\",101);
        System.out.println(s1);
        Student s2 = new Student();
        s2.reset(\"Suresh\",100);
        System.out.println(s2);
        System.out.println(\"Object s and s1 equal: \"+s.equals(s1));
        System.out.println(\"Object s and s2 equal: \"+s.equals(s2));
       
       
    }
}
Student.java
 public class Student extends Person{
    private int studentNumber;
    public Student(){
       
    }
    public int getStudentNumber() {
        return studentNumber;
    }
    public void setStudentNumber(int studentNumber) {
        this.studentNumber = studentNumber;
    }
    public void reset(String newName, int newNumber){
        super.setName(newName);
        this.studentNumber = newNumber;
    }
    public String toString(){
        return super.toString()+\" Number: \"+getStudentNumber();
    }
    public boolean equals(Student s){
        if(hasSameName(this) && getStudentNumber() == s.getStudentNumber()){
            return true;
        }
        return false;
    }
 }
Person.java
 public class Person {
    private String name;
    public Person(){
       
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String toString(){
        return \"Name: \"+getName();
    }
    public boolean hasSameName(Person p){
        if(getName().equalsIgnoreCase(p.name)){
            return true;
        }
        return false;
    }
 }
Output:
Name: Suresh Number: 100
 Name: Ssekhar Number: 101
 Name: Suresh Number: 100
 Object s and s1 equal: false
 Object s and s2 equal: true


