|
Help with errors in code
I am hoping someone can help me figure out what is wrong with my coding. The assignment is to write a program that reads data from a specified file and stores the ouput in another file. The input has a list of 3 names (last, first) and a salary amount. The output is to read those 3 names (first, last) and have a new salary amount after computing a raise of 5%.
Here is my code:
/* Program to read employees names and pay rate from file, calculates raise in pay, and stores output in another file of each employees name and new pay rate.*/
import java.io.*; //package to use FileReader and PrintWriter
import java.util.Scanner;
public class LynchA6
{
public static void main(String[] args) throws IOException
{
String first_name; //variable to store employees' names
String last_name;
double payRate; //variable to show current pay
double payRaise; //variable to show .05 raise
double payIncrease; //variable to calculate rate * .05
double newPay; // variable to show calculated new pay rate
Scanner inFile = new Scanner(new FileReader ("Assign6Data.txt")); //calls contents of file
PrintWriter outFile = new PrintWriter("Assign6Out.txt"); //where output is to be saved
while (inFile.hasNext()) //loop to visit each line
{
last_name = inFile.next();
first_name = inFile.next();
payRate = inFile.nextDouble();
newPay = payRate + (payRate * .05);
}//end while loop
outFile.printf("%-6s %-6s %7.2f %c %n", first_name, last_name, "$"+newPay); //output with spacing for name and pay
inFile.close();
outFile.close();
}
}
The error I get reads:
----jGRASP exec: javac -g LynchA6.java
LynchA6.java:30: variable first_name might not have been initialized
outFile.printf("%-6s %-6s %7.2f %c %n", first_name, last_name, "$"+newPay); //output with spacing for name and pay
^
LynchA6.java:30: variable last_name might not have been initialized
outFile.printf("%-6s %-6s %7.2f %c %n", first_name, last_name, "$"+newPay); //output with spacing for name and pay
^
LynchA6.java:30: variable newPay might not have been initialized
outFile.printf("%-6s %-6s %7.2f %c %n", first_name, last_name, "$"+newPay); //output with spacing for name and pay
^
3 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
|