public static void sortByNumber(Course[] list) {
Course temp = new Course();
boolean fixed = false;
while(fixed == false) {
fixed = true;
for (int i = 0; i<list.length-1; i++) {
if (list[i].getNum() > list[i+1].getNum()) {
temp.setNum(list[i].getNum());
temp.setDept(list[i].getDept());
temp.setTitle(list[i].getTitle());
list[i] = list[i+1];
list[i+1] = temp;
fixed = false;
}
}
}}
This is a method for sorting courses offered by university.
For example, each course has its department (i.e. MATH), number (i.e. 263) and title (i.e. Ordinary Differential Equations for Engineers) - MATH 263 Ordinary Differential Equations for Engineers.
In my another class, I have created an object Course, which has its own accessors and mutators (i.e. getNum(), setNum(), getDept(), so on).
Given a long list of courses, I wanted to arrange them according to their course numbers, but the above method does not seem to work.
Can someone hint reason for this?