I have an assignment where I need to create a Student class where you store the student's neptun code (String nep_c) and the number of points you have achieved in the exam (int point_num). Prepare a public int getMark () method that returns the ticket obtained to the exam as a function of the score according to the following table:
- between 100 and 90- > 5;
- between 90 and 80 -> 4;
- between 80 and 70 -> 3
- between 70 and 60 -> 2
- < 60 -> 1
The class implements the Comparable interface and the compareTo () method sort the students based on the neptun code. Within it, by the number of mark you get. Unfortunately I don't understand comperTo method. Can you help me how can I write the correct code?
public class Student implements Comparable{
private String nep_c;
private int point_num;
private int Mark;
public Student(int point_num, String nep_c) {
this.point_num = 65;
this.nep_c= "AAA1BB1";
}
public int getMark(){
if (point_num <= 100 && point_num > 90)
Mark = 5;
else if (point_num <= 90 && point_num > 80)
Mark = 4;
else if (point_num <= 80 && point_num > 70)
Mark = 3;
else if (point_num <= 70 && point_num > 60)
Mark = 2;
else if (point_num <= 60)
Mark = 1;
else{
return 0;
}
return Mark;
}
public String getNep_c(){
return nep_c;
}
public int getPoint_num(){
return point_num;
}
@Override
public int compareTo (Object o){
return ???;
}
}
Comparable
, if you haven't already. This question may also help: stackoverflow.com/questions/21626439 – CarafeMark
field is redundant, and it's dangerous because unless you callgetMark()
, it's value is wrong. – Uniformity