I am creating a hotel program which has an array filled with objects (Room), and each Room is filled with a customer name. I used an exchange sort to sort the array alphabetically, however I keep getting an error that Room cannot be converted into a String. I am fairly new to Java and I am struggling to find a fix to this. This is my sort below. How could I overcome this issue?
private static void orderedView(Room hotelRef[]) {
for (int i = 0; i < hotelRef.length; i++) {
for (int j = i + 1; j < 12; j++) {
if (hotelRef[i].compareTo(hotelRef[j]) > 0) {
String temp;
temp = hotelRef[i];
hotelRef[i] = hotelRef[j];
hotelRef[j]= temp;
}
}
}
System.out.print("Names in Sorted Order:");
for (int i = 0; i < hotelRef.length - 1; i++) {
System.out.println(hotelRef[i] + " ");
}
System.out.print(hotelRef[12 - 1]);
}