0

尝试运行此代码时,我收到“找不到符号”错误。这是关于 List 代码行的。它把它扔在 List 和 ArrayList 上。我无法弄清楚这是如何错误地实施的。该脚本调用一个名为 Employee 的类。该列表将包含从 Employee 创建的所有对象。然后应该可以打印列表了。

import java.util.Scanner;

class PayrollProgram
{


public static void main(String[] args)
{
    Scanner scan = new Scanner(System.in);

    List<Employee> employees = new ArrayList<>();

    while (!emp.name.equals("STOP"))
    {
    Employee emp = new Employee();

    System.out.print("Employee's Name: ");
    emp.name = scan.next();

    if(emp.name.equals("STOP"))
        {
            System.out.printf("The Application is STOPPING......");
        break;
        }

    System.out.print("Enter hourly wage: $ ");
    emp.wage = scan.nextDouble();
    while (emp.wage < 0) 
    {
        System.out.printf("Please Enter a Positive Number! \n");
        System.out.print("Enter hourly wage: $ ");  
        emp.wage = scan.nextDouble();
    }

    System.out.print("Hours Worked in Week: ");
    emp.hours = scan.nextDouble();
    while (emp.hours < 0) 
    {
        System.out.printf("Please Enter a Positive Number! \n");
        System.out.print("Hours Worked in Week: ");
        emp.hours = scan.nextDouble();
    }

    employees.add(emp);
    emp.printEmployee();

    }
    for(Employee emp : employees)
        {
        System.out.println(emp.name);
        }
}

}
4

2 回答 2

5

您既不导入java.util.List也不导入java.util.ArrayList。你应该这样做。

Employee如果您已在单独的包中定义了该类,您还需要导入您的类。

于 2013-10-16T03:04:11.230 回答
1

您应该导入正确的包并且您应该在 while 循环之前创建员工对象

Employee emp = new Employee();
while (!emp.name.equals("STOP"))
{

System.out.print("Employee's Name: ");
emp.name = scan.next();

if(emp.name.equals("STOP"))
    {
        System.out.printf("The Application is STOPPING......");
    break;
    }

System.out.print("Enter hourly wage: $ ");
emp.wage = scan.nextDouble();
while (emp.wage < 0) 
{
    System.out.printf("Please Enter a Positive Number! \n");
    System.out.print("Enter hourly wage: $ ");  
    emp.wage = scan.nextDouble();
}

System.out.print("Hours Worked in Week: ");
emp.hours = scan.nextDouble();
while (emp.hours < 0) 
{
    System.out.printf("Please Enter a Positive Number! \n");
    System.out.print("Hours Worked in Week: ");
    emp.hours = scan.nextDouble();
}

employees.add(emp);
emp.printEmployee();

}
于 2013-10-16T03:22:04.727 回答