-2

请我需要帮助,我正在努力让我的代码正常工作。该代码应该读取名为 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());
 }
}

输出错误

发现 2 个错误和 2 个警告:

* 错误 *

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
4

1 回答 1

2

尝试删除 print String employees(employees);并编写return employees; 和更改您的代码

public double getWage()
 {
  return getWage;
 }

 public double getWage()
 {
  return wage;
 }

这是因为,您没有初始化或声明getWage变量。

于 2013-10-18T01:16:32.660 回答