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

I need some assistance with a program that will read the data file that I create

ID: 3553751 • Letter: I

Question

I need some assistance with a program that will read the data file that I created from a previous program.

How do I copy that data file into the root directory of the Project Folder that you create for this program?

The data file I created contained records with an employee's name, the number of hours they worked, and their hourly pay rate.  

Write a program to read the records of information and output (to the Output window or a dialog box) the employee's name and their Gross Pay.

Compute their gross pay by using the following formulas:

If the employee worked 40 hours or less, their pay should be: hours * hourlyPayRate

But if the employee worked more than 40 hours, they get paid their regular amount for the first 40 hours plus "time and a half" for the hours worked over 40. Time and a half means 1.5 times their hourly pay rate. Use the following formula: (40 * hourlyPayRate) + (hours-40) * 1.5 * hourlyPayRate


This is the code from the previous project that creates the output to a file:


package output.to.a.file.broc.east;


import java.io.BufferedWriter;

import java.io.File;

import java.io.FileWriter;

import java.io.IOException;

import javax.swing.JOptionPane;


public class OutputToAFileBrocEast

{   

public static void main(String[] args)

{

try{

File file = new File("payroll.txt");

  

if (!file.exists()) {


file.createNewFile();


}

FileWriter fw = new FileWriter(file.getAbsoluteFile());


BufferedWriter bw = new BufferedWriter(fw);


String name;

String rate;

String hours;

String answer;

  

do {


name = JOptionPane.showInputDialog ("Enter first and last name: ");

rate = JOptionPane.showInputDialog ("Enter hourly rate: ");

hours = JOptionPane.showInputDialog ("Enter hours for previous week: ");


bw.write(""" + name + """ );

bw.write(" " + rate + " ");

bw.write(" " + hours + " ");

bw.write(" " );


answer = JOptionPane.showInputDialog ("Do you have another employee? [y/n]");


}

  

while (answer.equalsIgnoreCase ("y"));

  

bw.close();

}

catch (IOException e) {


e.printStackTrace();


}


}

  

}

Explanation / Answer

Just make sure the file name is payroll.txt and then move that file in project folder. If you are in windows just copy it, else in linux use command "cp" for copying.