Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

in the space provided. 16) (20 points) Define a class named Student that contain

ID: 3737408 • Letter: I

Question

in the space provided. 16) (20 points) Define a class named Student that contains: An int data field named age that stores the age of a student. . A String data field named sid that represents the student id. A constructor that accepts and creates a student object with the specified age and student id. The getter and setter methods for all data field. A toString method that returns student information including the student id and age. The equals method that returns true if two students have same id's and false otherwise. .A method findYoungest0 that returns the youngest student object.

Explanation / Answer

Student.java

public class Student {

private int age;

private String sid;

public Student(String sid, int age) {

this.age = age;

this.sid = sid;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

public String getSid() {

return sid;

}

public void setSid(String sid) {

this.sid = sid;

}

public String toString() {

return "Student ID: "+sid+" Age: "+age;

}

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != obj.getClass())

return false;

Student other = (Student) obj;

if (age != other.age)

return false;

if (sid == null) {

if (other.sid != null)

return false;

} else if (!sid.equals(other.sid))

return false;

return true;

}

public Student findYoungest(Student s) {

if(s.getAge() < age) {

return s;

}

return this;

}

}