/* DisplayEmployeeFileR.java CIS 111 Dave Klick 2013-11-19 Reads in random access file data and displays it. */ // CIS111App requires a class to represent a R/A record // This class represents a fixed-length record on disk class Record { // String variables must be initialized to the size the // String should be when it is stored on disk String name = "12345678901234567890"; String dept = "12345"; double rate; } public class DisplayEmployeeFileR extends CIS111App { public static void main(String[] args) { // 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); // Display headings for report println("Name Dept Rate"); println("---------- ------ -------"); // Process each record for (long recnum=1; recnum<=file.numberOfRecords(); recnum++) { // Read record at position recnum from file and store in rec // Note: record numbering starts at 1 rec = file.get(recnum); printf("%-10s %-6s %7.2f\n", rtrim$(rec.name), rec.dept, rec.rate); } file.close(); } }