我正在关注一个问题,但是我收到了这个错误。我不确定如何修复它,我已经查找了这个错误,但我无法将其与我的代码联系起来。非常感谢任何帮助!
import java.util.Scanner;
public class Employee {
private static String name;
private static String job;
private static float salary;
private static int id;
public Employee() {
Scanner scan = new Scanner(System.in);
name = scan.nextLine();
job = scan.nextLine();
salary = scan.nextFloat();
id = scan.nextInt();
}
public Employee(String name, String job, float salary, int id) {
name = name;
job = job;
salary = salary;
id = id;
}
public String getName(name) {
return name;
}
public String getJobTitle(job) {
return job;
}
public float salary(salary){
return salary;
}
public static void showEmp() {
System.out.println("Employee is called: " + name);
System.out.println("They are a " +job);
System.out.println("Their salary is " + salary);
System.out.println("Their Employee ID number is " + id);
}
}
答案 0 :(得分:0)
你的吸气者不应该有一个参数:
public String getName() {
return name;
}
变量也不应该是showEmp方法的静态。 完整代码应如下所示:
import java.util.Scanner;
public class Employee {
private String name;
private String job;
private float salary;
private int id;
public Employee() {
Scanner scan = new Scanner(System.in);
name = scan.nextLine();
job = scan.nextLine();
salary = scan.nextFloat();
id = scan.nextInt();
}
public Employee(String name, String job, float salary, int id) {
this.name = name;
this.job = job;
this.salary = salary;
this.id = id;
}
public String getName() {
return name;
}
public String getJobTitle() {
return job;
}
public float salary() {
return salary;
}
public void showEmp() {
System.out.println("Employee is called: " + name);
System.out.println("They are a " + job);
System.out.println("Their salary is " + salary);
System.out.println("Their Employee ID number is " + id);
}
}