-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStudent.java
More file actions
44 lines (33 loc) · 985 Bytes
/
Student.java
File metadata and controls
44 lines (33 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
public class Student implements Comparable<Student>{
private String name;
private int score;
public Student(String name, int score){
this.name = name;
this.score = score;
}
@Override
public int compareTo(Student another){
// if(this.score < another.score)
// return -1;
// else if(this.score == another.score)
// return 0;
// return 1;
// return this.score - another.score;
return another.score - this.score;
}
@Override
public boolean equals(Object student){
if(this == student)
return true;
if(student == null)
return false;
if(this.getClass() != student.getClass())
return false;
Student another = (Student)student;
return this.score == another.score;
}
@Override
public String toString(){
return String.format("Student(name: %s, score: %d)", name, score);
}
}