/* AddToEmployeeFileR.java CIS 111 Dave Klick 2013-11-19 Gets data from user and writes it to a random access file. */ // 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 AddToEmployeeFileR 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); // Get number of records already in file // Note: record numbering starts at 1 int recnum = (int) file.numberOfRecords(); // Read data from user and store in the Record object while ((rec.name = getString("Enter name (Enter to quit): ")).length() > 0) { rec.dept = getString("Enter department: "); rec.rate = getDouble("Enter hourly rate: ", 0.0, 1000.0); // Increase record number recnum++; // Write record to end of file file.put(recnum, rec); } file.close(); } }