I have this class and I just need help with the toString() inside the methods to actually show the result. It gives me an error that I can’t use getName() or getId() in a static context :
public static void bubbleSort(Student[] array)
{
for(int i=(array.length); i>0; i--)
for(int j=1; j<(array.length-i); j++)
if(array[j].getName().compareTo(
array[j+1].getName())<0) {
Student Temp = array[j];
array[j] = array[j+1];
array[j+1] = Temp;
}
String s = null;
for (int i=0; i<array.length; i++) {
// the error is here under the getName and getId
s= s+ getName()+" "+ getId() ;
}
System.out.print (s);
}
I think you want to print the names and IDs of the
Students you previously sorted.The methods
getName()andgetID()belong to the objectStudentand are not methods of the class wherebubbleSort()is defined.