COMPILE TIME ERROR EmployeeIDGeneration/src/UserInterface.java:1: error: class EmployeeIdGenerator is public, should be declared in a file named EmployeeIdGenerator.java public class EmployeeIdGenerator { ^ EmployeeIDGeneration/src/UserInterface.java:4: error: cannot find symbol Scanner sc = new Scanner(System.in); ^ symbol: class Scanner location: class EmployeeIdGenerator EmployeeIDGeneration/src/UserInterface.java:4: error: cannot find symbol Scanner sc = new Scanner(System.in); ^ symbol: class Scanner location: class EmployeeIdGenerator 3 errors
Question
COMPILE TIME ERROR EmployeeIDGeneration/src/UserInterface.java:1: error: class EmployeeIdGenerator is public, should be declared in a file named EmployeeIdGenerator.java public class EmployeeIdGenerator { ^ EmployeeIDGeneration/src/UserInterface.java:4: error: cannot find symbol Scanner sc = new Scanner(System.in); ^ symbol: class Scanner location: class EmployeeIdGenerator EmployeeIDGeneration/src/UserInterface.java:4: error: cannot find symbol Scanner sc = new Scanner(System.in); ^ symbol: class Scanner location: class EmployeeIdGenerator 3 errors
Solution
The error messages you're seeing are due to two main issues:
-
The public class
EmployeeIdGeneratorshould be declared in a file namedEmployeeIdGenerator.java. Java requires that public classes are in their own files, and the file name must match the class name. So, you should either rename your file toEmployeeIdGenerator.javaor change the class name to match the file name. -
The
Scannerclass is not found. This is likely because you haven't imported it. At the top of your file, you should add the lineimport java.util.Scanner;to import the Scanner class from the Java standard library. This class is used for reading input, and it's necessary to import it before you can use it in your code.
So, your corrected code should look something like this:
import java.util.Scanner;
public class EmployeeIdGenerator {
// your code here
Scanner sc = new Scanner(System.in);
// more of your code
}
Remember to save this in a file named EmployeeIdGenerator.java.
Similar Questions
COMPILE TIME ERROR ResortBooking/src/UserInterface.java:27: error: cannot find symbol Booking booking = new Booking(customerName, numAdults, numChildren, numDays); ^ symbol: class Booking location: class UserInterface ResortBooking/src/UserInterface.java:27: error: cannot find symbol Booking booking = new Booking(customerName, numAdults, numChildren, numDays); ^ symbol: class Booking location: class UserInterface 2 errors
COMPILE TIME ERROR StudentDetails/src/UserInterface.java:16: error: constructor Student in class Student cannot be applied to given types; student = new Student(id, name, address); ^ required: int,String,String,String found: int,String,String reason: actual and formal argument lists differ in length 1 error
Main.java:3: error: class Person is public, should be declared in a file named Person.javapublic class Person { ^Main.java:15: error: class Student is public, should be declared in a file named Student.javapublic class Student extends Person { ^Main.java:24: error: class Employee is public, should be declared in a file named Employee.javapublic class Employee extends Person { ^Main.java:34: error: class Faculty is public, should be declared in a file named Faculty.javapublic class Faculty extends Employee { ^Main.java:44: error: class Staff is public, should be declared in a file named Staff.javapublic class Staff extends Employee { ^5 errors
/home/ubuntu/b7a1d422-9b79-414d-9c33-672d9242a6ea/Main.java:3: error: class EMICalculator is public, should be declared in a file named EMICalculator.javapublic class EMICalculator { ^1 error
Given the following code, find the compile error. Please select all that apply. public class Test { public static void main(String[] args) { m(new GraduateStudent()); m(new Student()); m(new Person()); m(new Object()); } public static void m(Student x) { System.out.println(x.toString()); } } class GraduateStudent extends Student { } class Student extends Person { @Override public String toString() { return "Student"; } } class Person extends Object { @Override public String toString() { return "Person"; } } Group of answer choicesm(new GraduateStudent()) causes an errorm(new Student()) causes an errorm(new Person()) causes an errorm(new Object()) causes an error
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.