如何修复语法错误,插入" ... VariableDeclaratorId ..."

时间:2017-03-29 13:42:44

标签: java

我正在关注一个问题,但是我收到了这个错误。我不确定如何修复它,我已经查找了这个错误,但我无法将其与我的代码联系起来。非常感谢任何帮助!

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);
}

}

This is the question

1 个答案:

答案 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);
    }
}