Question: 1)With the DataInputStream class: the read method can only read one character at a time. the read method can read only one record at a
| 1)With the DataInputStream class: the read method can only read one character at a time. the read method can read only one record at a time. the read method can read more than one record at a time. the read method can read only one field at a time. 2)Which of the following is true? You open a file by creating the appropriate object. You close a file by deleting the appropriate object. Two of these answers are correct. The DataOutputStream class is used to write to a printer. 3)The BufferedInputStream class is used to read characters from a file. An object of the File class is required in order to read data from or write data to files. in order to get information about files. in order to read data from but NOT write data to files. in order to write data to but NOT read data from files. two of these answers are correct. With the following code: filePosition = employeeID%100; employeeFile.seek(filePosition * RECORDSIZE); NOT ON THE EXAM!!!!! The maximum random access record size is 100 characters. The maximum number of random access records depends on the values of filePosition and RECORDSIZE. The maximum number of random access records depends on the value of RECORDSIZE. The maximum number of random access records is 100. The maximum number of random access records cannot be determined with this code. How many records will be written to the newMasterFile? Cannot calculate this based on the code. The same as that in the oldMasterFile. An amount equal to that in the oldMasterFile plus the transaction file. The same as that in the transactionFile. How many fields are there in each transactionFile record? The number of fields depends on how many the user enters. There are three fields There are one to three fields, depending on the record. There are zero to two fields. What would happen if you replaced payRate = oldMasterFile.readFloat(); ytdGrossPay = oldMasterFile.readFloat(); with ytdGrossPay = oldMasterFile.readFloat(); payRate = oldMasterFile.readFloat(); Everything would work OK. There would be a compile error. The program would run but calculations would be wrong. The program would stop with an error when ytdGrossPay = oldMasterFile.readFloat(); was executed If you opened the oldMasterFile in TextPad, which fields would you be able to understand? payRate and ytdGrossPay only you would not be able to understand any fields. oldMastKey and address only. All fields What would happen if you deleted address = oldMasterFile.readUTF(); The program would run but calculations would be wrong. The program would stop with an error when payRate = oldMasterFile.readFloat(); was executed. Everything would work OK. There would be a compile error. | //note: Assume data are good and files are in the correct order. import java.io.*; public class Payroll { private static DataInputStream transactionFile, oldMasterFile; private static DataOutputStream newMasterFile; private static String transKey, oldMastKey, newMastKey, address, END_OF_FILE = "zzz"; private static double payRate, currentGrossPay, currentNetPay, ytdGrossPay, currentHoursWorked, currentDeductions; public static void main (String[] args)throws Exception { transactionFile = new DataInputStream (new FileInputStream ("trans.txt")); oldMasterFile = new DataInputStream(new FileInputStream ("omas.txt")); newMasterFile = new DataOutputStream (new FileOutputStream("nmas.txt")); ReadTransaction(); ReadOldMaster(); while(!(transKey == END_OF_FILE && oldMastKey == END_OF_FILE)) { if(transKey.compareTo(oldMastKey)>0) { WriteNewMaster(); ReadOldMaster(); } else { ProducePaycheck(); UpdateYTDFields(); ReadTransaction(); WriteNewMaster(); ReadOldMaster(); } } } private static void ReadTransaction()throws Exception { try { transKey = transactionFile.readUTF(); currentHoursWorked = transactionFile.readFloat(); currentDeductions = transactionFile.readFloat(); } catch (EOFException endOfFile) { transKey = END_OF_FILE; } } private static void ReadOldMaster()throws Exception { try { oldMastKey = oldMasterFile.readUTF(); address = oldMasterFile.readUTF(); payRate = oldMasterFile.readFloat(); ytdGrossPay = oldMasterFile.readFloat(); } catch (EOFException endOfFile) { oldMastKey = END_OF_FILE; } } private static void WriteNewMaster()throws Exception { newMasterFile.writeUTF(oldMastKey); newMasterFile.writeUTF(address); newMasterFile.writeFloat(payRate); newMasterFile.writeFloat(ytdGrossPay); } private static void UpdateYTDFields() { ytdGrossPay += currentGrossPay; } private static void ProducePaycheck() { currentGrossPay = currentHoursWorked * payRate; currentNetPay = currentGrossPay - currentDeductions; } } |
please show all work!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
