Question: Write a class named Student with attributes student ID , name, and age. The class implements the Comparable interface. Please override the following methods: -
Write a class named Student with attributes student ID name, and age. The class implements the
Comparable interface. Please override the following methods:
Equals method such that two students are equal if they have the same id
HashCode method such that it returns an integer based on student id
CompareTo method such that a student with a higher age is greater than the student with a
lower age
Now,
Create two students students have different id name, and age
Create two students students have the same id but different name and age
Create three students students have different id and name but same age
Add the students to a HashSet. Does it allow duplicates?
Add the students to a TreeSet. Does it allow duplicates?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
