0

I'm receiving a "can't find symbol" error when trying to run this code. It's in regard to the List line of code. It is throwing it on the List and ArrayList. I can't figure how this is implemented wrong. The script calls a class called Employee. The List is to contain all objects created from Employee. Then should be able to print the List.

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);
 }
}
}
asked Oct 16, 2013 at 3:01
0

2 Answers 2

5

You've imported neither java.util.List nor java.util.ArrayList. You should do that.

You also need to import your Employee class, if you've defined that in a separate package.

answered Oct 16, 2013 at 3:04
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks that fixed one problem. Now I'm recieving an error on the for loop saying the variable emp is already defined in the main method. If I take out the Employee declatation for emp, I receive errors saying "not a statement", "; excepted", ": illegal start of statement"
@AwayFromMyDesk, change this: while (!emp.name.equals("STOP")) to this: while (true).
1

YOU should import correct packages & also you should create the Object of employee before while loop

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();
}
answered Oct 16, 2013 at 3:22

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.