Lab assignment: Sorting.

The topic of the lab today is sorting arrays in java. You need to implement a sorting algorithm, named Bubble Sort to sort an array of Jobs (lab 6) in increasing or decreasing order of hourly rate. An example of Bubble Sort for an array of integers is here. The idea of Bubble Sort is to compare adjacent elements of the array and swap them according to the sorting order. Bubble Sort goes over the array of elements many times, each time swapping elements. In the example the array of integers is being sorted in ascending order, so smaller number must go first. Every time the algorithm discovers that a larger number comes before a smaller adjacent number it swaps them. (Notice
if ( theArray[ current] > theArray[ current+1]) ).

For the lab today you need to implement Bubble Sort for an array of Jobs, instead of numbers. You can reuse your Job.java from lab 6, or use the code provided below:

Job.java
Driver.java

Stage 1:
Create a method named greaterThan( Job otherJob) for the class Job that returns true if the calling object has hourly rate greater than the parameter. This method implements the > comparison for the jobs. The example of Bubble Sort provided above compares integers, therefore is not suited for Job objects. The greaterThan method has the same meaning as the > operator for integers, only it works with Job objects.

Stage 2:
The Driver class contains an array of 10 jobs that has already been created. Modify the code of Bubble Sort so that it works with the array of 10 jobs provided in the class Driver. You only need to substitute the > operator inside the if with the greaterThan method from stage 1. Sort the array of jobs using the modified bubble sort. Print the sorted array in output.


Stage 3 (Advanced):
Create a method called comparison, that is very similar to greaterThan but has a second parameter that is used to indicate if the sort is ascending (or else is descending).  This would look like:
         public boolean comparison( Job otherJob, boolean sortAscending)
         // return true if the calling object has hourly rate greater than the parameter and sortAscending is true, else return false.

Solution:

Driver.java
Job.java