Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

WARNING: In line 6 on page 241, I indicated that the file will be created on the

ID: 666587 • Letter: W

Question

WARNING: In line 6 on page 241, I indicated that the file will be created on the C: drive at: C: emp. DO NOT specify a drive or path in your program! Only put the name of the file that you want to create such as:

pay = new OutputFile("payroll.txt");

The file will be created at the root of the Project Folder. You will be able to see the file that was created by selecting the Files tab in NetBeans.

Write a program to get input from the user using dialog boxes. The program should repeatedly input 3 pieces of information: An employee's full name, their hourly rate of pay, and the total number of hours that they worked during the previous week. The program should write this information to an OutputFile object. When this program ends, you will have a text file that will have records with 3 fields of information in each record and would look something

"Bob Jones" 40.0 10.25

"Sam Smith" 45.5 15.00

"Jodi White" 32.25 20.50

etc.

Notice that the name has quotes around it (use the writeString( ) method to automatically put quotes around the employee's name). You can use any method you choose to stop the program. Be sure to close the OutputFile at the very end of the program or the data will not appear in the file.

Explanation / Answer

Answer:

Note:Here your modified code

    payFile = new OutputFile("payroll.txt");/ /here you have enter only the text file name with txt extension no need to specify full path

code

import javax.swing.JOptionPane;

public class phoneFileWriter

{

public static void main(String[] args)

{

    OutputFile payFile;

    payFile = new OutputFile("payroll.txt");

    String name;

    Double pay, hours;

    String answer;

    Keyboard k;

    k = new Keyboard();

    do

    {

        name = JOptionPane.showInputDialog("Enter the employee's name:");

        pay = Double.parseDouble(JOptionPane.showInputDialog("Enter the employee's hourly wage:"));

        hours = Double.parseDouble(JOptionPane.showInputDialog("Enter the employee's total hours:"));

        payFile.writeString(name);

        payFile.writeDouble(pay);

        payFile.writeDouble(hours);

        payFile.writeEOL();

        answer = JOptionPane.showInputDialog("Do you have another employee to enter? (yes/no)");

    } while (answer.equalsIgnoreCase("yes"));

    payFile.close();

}

}