我需要帮助,我正在努力让我的代码正常运行。该代码应该读取名为A2Q1in.txt的.txt文件,并使用loadEmployees方法打印出该文件包含的所有信息。编译代码时,我得到2个错误,我不知道如何修复它们,请看看问题末尾的输出。
代码:
mport java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class A2Q1
{
public static void main(String[] parms)
{
Employee [] employees ;
String [] array_;
array_ = new String [50];
employees = loadEmployees();
System.out.println("\nProgram completed normally.");
}
public static Employee[] loadEmployees()
{
Employee[] employees;
BufferedReader fileIn;
String inputLine;
try
{
fileIn = new BufferedReader(new FileReader("A2Q1in.txt"));
inputLine = fileIn.readLine();
while (inputLine != null)
{
System.out.println(inputLine);
inputLine = fileIn.readLine();
}
fileIn.close();
}
catch (IOException ioe)
{
System.out.println(ioe.getMessage());
}
print String employees(employees);
}
}
/*********************************************************************/
/*********************************************************************/
class Employee
{
private String employeecomany;
private String name;
private String division;
private Double wage;
public Employee(String employeecomany, String name, String division, Double wage)
{
this.employeecomany = employeecomany;
this.name = name;
this.division = division;
this.wage = wage;
}
public double getWage()
{
return getWage;
}
public String toString()
{
return String.format("%-10s %3d $%4.2f $%5.2f ", employeecomany, name, division, getWage());
}
}
输出错误
File: C:\Users\samiralbayati\Desktop\Comp 1020 JAVA assignment 2\A2Q1.java [line: 39]
Error: Syntax error, insert ";" to complete LocalVariableDeclarationStatement
File: C:\Users\samiralbayati\Desktop\Comp 1020 JAVA assignment 2\A2Q1.java [line: 68]
Error: getWage cannot be resolved to a variable
答案 0 :(得分:2)
尝试删除print String employees(employees);
并撰写return employees;
并更改您的代码
public double getWage()
{
return getWage;
}
到
public double getWage()
{
return wage;
}
这是因为您没有初始化或声明getWage
变量。