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

I am having a problem with a program and would like to know what to do to fix it

ID: 3569577 • Letter: I

Question

I am having a problem with a program and would like to know what to do to fix it.

import java.io.*;
import java.text.*;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Employees_3_10 {

public static void main (String[]args) throws Exception {

Scanner input = new Scanner(System.in);

final String INPUT_FILE = "Employees_3_08_Input.txt";
final String OUTPUT_FILE = "Employees_3_08_Output.txt";

File inputDataFile = new File(INPUT_FILE);
Scanner inputFile = new Scanner(inputDataFile);
FileWriter outputDataFile = new FileWriter(OUTPUT_FILE);
PrintWriter outputFile = new PrintWriter(outputDataFile);
System.out.println("Reading file " + INPUT_FILE + " " +
"Creating file " + OUTPUT_FILE);


int wages = 0, hours = 0, numofEmployees = 0;
double grosspay = 0, withholdings = 0, netpay = 0, overtime;
double [][] data = new double [30][7];
String [] names = new String [30];
String str = null;
String detail = null;
int n = input(data, names, inputFile); //n is name counter 25 total.

if (hours < 40)
{
grosspay = hours*wages;
}
else if (hours >= 40)
{
grosspay = hours*wages + ((hours-40)*wages*1.5);
}
else if (hours > 50)
{
grosspay = hours*wages + ((50-40)*wages*1.5) + ((hours-50)*wages*2);
}


report(outputFile,names, n);


report(outputFile, names, n);


report(outputFile, names, n);

outputFile.close();
}
//************************************************** ****************************************
public static int input(double [][] data, String [] names, Scanner inputFile)
{int i = 0;
int m = 0;
String line;
StringTokenizer st;
while (inputFile.hasNext() && i < names.length)
{line = inputFile.nextLine();
st = new StringTokenizer(line);
m = st.countTokens();
names [i] = st.nextToken();
for (int j = 1; j < m-2; j++)
names [i] = names [i] + " " + st.nextToken();
data [i][5] = Double.parseDouble(st.nextToken());
data [i][6] = Double.parseDouble(st.nextToken());
i++;}
return i;
}  

//************************************************** ****************************************
public static String report(PrintWriter outputFile, String[]names, int n)
{//outFile.println(heading());
//outFile.println(summary(n));
return (detail(outputFile,names, n));
outputFile.println(" ");}

//************************************************** ****************************************
public static String heading()
{return " NATURAL PINE FURNITURE COMPANY" +
" PAYROLL REPORT" +
" -----------------------------------------------------------------------" +
"---------------------" +
" NAME" + " " + "NET PAY" + " " + "GROSS PAY" + " " +
"FEDERAL TAX" + " " + "STATE TAX" + " " + "DUES" + " " +
"HOURS" + " " + "PAY RATE" +
" -----------------------------------------------------------------------"
+ "---------------------";}
//************************************************** ****************************************
public static void detail(PrintWriter outputFile, String [] names, int n)
{for (int i = 0; i < n; i++)
outputFile.println(names[i]);}
//************************************************** ****************************************
public static String summary(int n)
{return " -----------------------------------------------------------------------" +
"---------------------" +
" -----------------------------------------------------------------------" +
"---------------------" +" The total number of names processed is " + n;


}
}

This is the error I'm getting:

Employees_3_10.java:78: error: incompatible types: void cannot be converted to String
return (detail(outputFile,names, n));
^
1 error

Can someone help?

Explanation / Answer

Yours return type of detail() is void
public static void detail(PrintWriter outputFile, String [] names, int n)
and return type of report is String
public static String report(PrintWriter outputFile, String[]names, int n)
but report() calls detail() in return ,in short report returns void,which should have been srting
so,just modify as below
public static String report(PrintWriter outputFile, String[]names, int n)
{//outFile.println(heading());
//outFile.println(summary(n));
detail(outputFile,names, n);//just call detail function
return NULL;

outputFile.println(" ");
}