2017-03-29 40 views
-1

我在跟隨一個問題,但我得到這個錯誤。我不知道如何解決它,我查了這個錯誤,但我不能把它與我的代碼。希望得到任何幫助!如何解決語法錯誤,插入「... VariableDeclaratorId ...」

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

回答

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

這就解決了,謝謝。 –

相關問題