Examlex

Solved

Import Java.nio.file.*; Import Java.io.*;

question 17

Short Answer

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.


Definitions:

Motion For A Directed Verdict

A motion, also known as a motion for judgment as a matter of law in the federal courts, requesting that the court grant a judgment in favor of the party making the motion on the ground that the other party has not produced sufficient evidence to support his or her claim.

Speedy Trial Motion

A legal motion filed to ensure a defendant is brought to trial within the legally mandated time frame.

Death Penalty

A legal sentence to death as punishment for a crime, also known as capital punishment.

Probation

When a convicted defendant is released from confinement but is still under court supervision for a period of time.

Related Questions