+ 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!

8th Oct 2017, 1:21 PM
Genadi Tsolov
Genadi Tsolov - avatar
5 Answers
+ 5
//mark Chrizzhigh answer as best //use \n to print every name with grade in next line
8th Oct 2017, 2:43 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 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
8th Oct 2017, 2:26 PM
Chrizzhigh
Chrizzhigh - avatar
+ 3
But i have to fill the array and sort the students by grade.
8th Oct 2017, 2:12 PM
Genadi Tsolov
Genadi Tsolov - avatar
+ 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
8th Oct 2017, 3:41 PM
Peerzada Burhan
Peerzada Burhan - avatar
0
instead of a student array, make separate variables for each student
8th Oct 2017, 1:59 PM
Joshua
Joshua - avatar