Help with java code

im pretty new to java coding and im having trouble getting one method to work. I would appreciate it ifsum could look at the following code in the runpayroll method to see where im going wrong as it will not compile

import java.io.FileReader;

import java.io.FileWriter;

import java.io.BufferedReader;

import java.io.PrintWriter;

import java.io.IOException;

import java.io.File;

/*******************************************************************************

* Textfile-based staff list with payroll, appointment, and redundancy functions

*

* @author Andrew Mackel

* @version 1.0

*******************************************************************************/

public class StaffList

{

// CONSTANTS ***************************************************************

final String STAFF_FILE = "staff.txt";

final String TEMP_FILE = "temp.txt";

final int[] PAYSCALE = {1000, 1050, 1100, 1150, 1200,

1300, 1400, 1600, 1800, 2000, 2500};

final int SEVERANCE_MULTIPLE = 3;

// INSTANCE VARIABLES ******************************************************

// CONSTRUCTORS ************************************************************

/**

* Constructor

*/

StaffList ()

{

// no actions

}

// METHODS *****************************************************************

// TO DO: write addStaffMember() method which appends a line to the staff

//file containing the number, name and grade of the new member

//of staff (tab separated)

// TO DO: write runPayroll() method which prints a header saying

//"XXX Payroll" where XXX is the month, then reads each record

//in the staff file and for each prints an advice of the form:

//

//Salary advice for Freda Bloggs

//Employee number: 42

//Employee grade: 6

//Monthly salary: ?400

//

//and finally returns the total cost of the month's payroll

/**

* Remove staff member from file and calculate severance payment

*

* @param pNum staff number

* @return severance payment due (or -1 if pNum not found in staff file)

*/

public int makeRedundant(int pNum)

{

String inputLine;

String[] inputFields;

int staffNum;

int staffGrade = -1;

int severance;

try

{

FileReader fr = new FileReader(STAFF_FILE);

BufferedReader br = new BufferedReader (fr);

FileWriter fw = new FileWriter(TEMP_FILE, false);

PrintWriter pw = new PrintWriter(fw);

inputLine = br.readLine();

while (inputLine != null)

{

inputFields = inputLine.split("\t");

staffNum = Integer.parseInt(inputFields[0]);

if (staffNum == pNum)

{

staffGrade = Integer.parseInt(inputFields[2]);

}

else

{

pw.println(inputLine);

}

inputLine = br.readLine();

}

fr.close();

fw.close();

if (staffGrade != -1)

{

File staffFile = new File(STAFF_FILE);

File tempFile = new File(TEMP_FILE);

staffFile.delete();

tempFile.renameTo(staffFile);

severance = PAYSCALE[staffGrade] * SEVERANCE_MULTIPLE;

}

else

{

severance = -1;

}

return severance;

}

catch (IOException ioe)

{

User.message("Unable to read/write from staff file");

User.message("EXCEPTION: " + ioe);

return -1;

}

}

public void addStaffMember (int pNum, String pName, int pGrade)

{

try

{

// create writers for output file (to append not overwrite)

FileWriter fw = new FileWriter(STAFF_FILE, true);

PrintWriter pw = new PrintWriter(fw);

// print pNum, pName and pGrade (TAB-separated) and close file

pw.println(pNum + "\t" + pName + "\t" + pGrade);

pw.close();

}

catch (java.io.IOException ioe)

{

// there has been an output error - display message and details

User.message("ERROR: unable to write to staff file");

User.message("EXCEPTION: " + ioe);

}

}

/**

* Display a list of all invoices and total on system console

*/

void runPayroll(String pMonth)

{

String inputLine;

String[] inputFields;

int pNum;

String pName;

int pGrade;

int total=0;

System.out.println("Payroll for the month of: " + pMonth);

try

{

// create readers for input file

FileReader fr = new FileReader(STAFF_FILE);

BufferedReader br = new BufferedReader(fr);

// read first line

inputLine = br.readLine();

// read lines of input until EOF

while (inputLine != null)

{

// split input line by tabs and assign fields to variables

inputFields = inputLine.split("\t");

pNum = inputFields[0];

// print invoice details and add to total

System.out.println("Staff Member: " + pNum + pName + pGrade + " - Salary: " + PAYSCALE);

total = total;

// read next line of input

inputLine = br.readLine();

}

// close file and print total

fr.close();

System.out.println("TOTAL: " + total);

}

catch (java.io.IOException ioe)

{

// there has been an input error - display message and details

User.message("ERROR: unable to read invoice file");

User.message("EXCEPTION: " + ioe);

}

}

}

[5518 byte] By [Mackel007a] at [2007-11-27 0:01:35]
# 1

1) use code tags

2) who or what is ifsum ? (In other words spell things out and make your message clear

3) it won't compile so it's likely giving you errors - those help people help you lots.

4) keep the code short - in other words if you are having problems in runpayroll post that to start as the rest is just taking attention away from your problem.

Aknibbsa at 2007-7-11 15:53:02 > top of Java-index,Java Essentials,Java Programming...