/* SortEmployeeFileR.java CIS 111 Dave Klick 2013-11-23 Reads in random access file data into an array, sort the data, then displays the data. */ // CIS111App requires a class to represent a R/A record // This class represents a fixed-length record on disk class Record { String name = "12345678901234567890"; String dept = "12345"; double rate; } public class SortEmployeeFileR extends CIS111App { public static void main(String[] args) { int i, j; // An example Record object is needed for CIS111App R/A Record rec = new Record(); // This opens the file for both input and output RandomFile file = new RandomFile("emp.jmg", rec); // Get number of records already in file // Note: record numbering starts at 1 int numrecs = (int) (file.numberOfRecords()); // Create an array of Record objects Record[] emp = new Record[numrecs]; // Read records into array for (int recnum=1; recnum<=numrecs; recnum++) { emp[recnum-1] = file.get(recnum); } file.close(); // Sort the records in the array for (i=0; i0 || (compDept==0 && compName>0)) { // Swap records Record temp = emp[i]; emp[i] = emp[j]; emp[j] = temp; } } } // Display sorted record // Output report to a text file instead of to the screen SequentialFile outfile = new SequentialFile("RandReport.txt", FileMode.OUTPUT); outfile.println("Name Dept Rate"); outfile.println("---------- ------ -------"); for (i=0; i