+ 2
Can someone help me with this code?
I have a homework to make a working school register with students names and grades, and sort them by grades. The code starts something like that: public class Student { public String name; public double grade; } class MyClass { public static void main(String[ ] args) { Student[] students = new Student [20]; .... } } Can someone tell me how to continue with the code? Thanks!
5 Answers
+ 5
//mark Chrizzhigh answer as best
//use \n to print every name with grade in next line
+ 4
If you dont have to use the array you can make it easier with Lists and Collections.sort
i made an example:
https://code.sololearn.com/cFk7ZXGu36Gi/#java
+ 3
But i have to fill the array and sort the students by grade.
+ 1
use treeMap:
eg:
TreeMap<String,String> map = new TreeMap<>();
map.put("9.5","Ramesh");
map.put("6.5","Suresh");
map.put("7.4","Mukesh");
Map<String,String> reverseMap = map.decendingMap();
for(Map.Entry m : reverseMap.entrySet()){
System.out.println(m.getKey() + " " + m.getValue());
}
This will put them in descending order with highest grade at the top
0
instead of a student array, make separate variables for each student