Examlex
import java.nio.file.*;
import java.io.*;
import java.nio.channels.FileChannel;
import java.nio.ByteBuffer;
import static java.nio.file.StandardOpenOption.*;
import java.util.Scanner;
public class CreateEmployeesRandomFile
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
Path file =
Paths.get("C:\\Java\\Chapter.13\\RandomEmployees.txt");
String s = "000, ,00.00" +
System.getProperty("line.separator");
final int RECSIZE = s.length();
FileChannel fc = null;
String delimiter = ",";
String idString;
int id;
String name;
String payRate;
final String QUIT = "999";
try
{
fc = (FileChannel)Files.newByteChannel(file, READ, WRITE);
System.out.print("Enter employee ID number >> ");
idString = input.nextLine();
while(!(idString.equals(QUIT)))
{
----Code here-----
System.out.print("Enter name for employee #" +
id + " >> ");
name = input.nextLine();
System.out.print("Enter pay rate >> ");
payRate = input.nextLine();
s = idString + delimiter + name + delimiter +
payRate + System.getProperty("line.separator");
byte[] data = s.getBytes();
ByteBuffer buffer = ByteBuffer.wrap(data);
----Code here-----
fc.write(buffer);
System.out.print("Enter next ID number or " +
QUIT + " to quit >> ");
idString = input.nextLine();
}
fc.close();
}
catch (Exception e)
{
System.out.println("Error message: " + e);
}
The above program will accept any number of employee records as user input and write the records to a file in a loop. In the first indicated line, create the statement to accept the employee data value from the keyboard as a String and convert it to an integer using the parseInt() method. In the second indicated line, create the statement to compute the record's desired position by multiplying the ID number value by the record size.
President Johnson
Likely refers to Lyndon B. Johnson, the 36th President of the United States, known for his domestic policies, including the Great Society programs.
Acquittal
The legal act of declaring someone not guilty of the charges against them in a court of law.
Congressional Reconstruction
The period after the Civil War during which the U.S. Congress implemented and enforced laws aiming to rebuild and reform the Southern states while securing civil rights for freed slaves.
Evolution
A scientific theory that explains the diversity of life on Earth through processes such as natural selection and genetic variation.
Q7: What is information hiding and how is
Q8: All of the following are used to
Q18: Carol Carr's motivation was most likely<br>A) Utilitarian<br>B)
Q23: What class is the immediate parent of
Q30: Label the following examples of Method II
Q32: Label the following as Normative (N) or
Q34: Label the following as Normative (N) or
Q36: You can create a writeable file by
Q43: When populating an array with an initialization
Q44: The true benefit of using a(n) _