import java.io.*;
import java.util.*;
class Student implements Comparable<Student>{
String name;
int rno;
Student(String name, int rno){
this.name = name;
this.rno = rno;
} // end of constructor
public boolean equals(Object o){
Student st = (Student)o;
return rno == st.rno;
}
public int compareTo(Student s){
return rno-s.rno;
}
public String toString(){
return name+" "+rno;
}
}
class demo{
public static void main(String args[]){
Console c = System.console();
int marks [] = new int[4];
TreeSet <Student> sinfo = new TreeSet<Student>();
TreeMap<Student,int[]> full_info = new TreeMap<>();
int no_student = Integer.parseInt(c.readLine("Enter the number of students: "));
for(int j = 0;j<no_student;j++){
String sname = c.readLine("Enter"+(j+1)+" Student name: ");
int srno = Integer.parseInt(c.readLine("Enter "+sname+"'s Roll.No. : "));
Student s = new Student(sname,srno);
sinfo.add(s);
int english = Integer.parseInt(c.readLine("Enter the marks of English: "));
int maths = Integer.parseInt(c.readLine("Enter the marks of Maths: "));
int hindi = Integer.parseInt(c.readLine("Enter the marks of Hindi: "));
int sci = Integer.parseInt(c.readLine("Enter the marks of Science: "));
for(int i = 0; i<marks.length; i++){
if(i == 0){marks[i]= english;}
else if(i == 1){marks[i]= maths;}
else if(i == 2){marks[i]=hindi;}
else{marks[i] = sci;}
}// end of for for marks entry
full_info.put(s,marks);
}
for (Map.Entry<Student, int[]>
entry : full_info.entrySet())
System.out.println(
"[" + entry.getKey()
+ ", " + entry.getValue() + "]");
}// end of main
}// end of demo
这是输出结果
我应该进行哪些更改才能使输出具有[10,20,30,40]而不是哈希码? 我应该在哪里覆盖toString方法以获取值?