2014-03-14 72 views
0

我該如何解決這個問題,我有...這是我的代碼,我工作,我似乎無法得到輸出。我不知道爲什麼會發生這種情況,我的意思是,最近它運行良好,我得到了輸出,但現在每次都得到這個錯誤。錯誤:找不到符號java

public static TimeCard processTimeCard(String data) 
{ 
    String[] split = data.split(","); 
    String employee = split[0]; 
    String project = split[1]; 
    double rate = Double.parseDouble(split[2]); 

    String[] days = { "Sunday", "Monday", "Tuesday", 
         "Wednesday", "Thursday", 
         "Friday", "Saturday"}; 

    Scanner keyboard = new Scanner(System.in); 

    // Get number of hours for each day of the week 
    for (int index = 0; index < days.length; index++) 
    { 
     System.out.println("How many hours on " + days[index] + "."); 
     double hours = Double.parseDouble(keyboard.nextLine()); 
    } 


    // Create a TimeCard object and return a reference to it. 
    return new TimeCard(employee, project, rate); 

} 

class TimeCard 
{ 
    // Instance Variables 
    private String employeeName; 
    private String project; 
    private double rate; 
    private double hours; 

    //Class Variables 
    private static int numCards = 0; 
    private static final double OT_MULTIPLIER = 1.5; 
    private static final int OT_LIMIT = 40; 


    /** 
    * Constructor 1 
    */ 
    public TimeCard(String employeeName, String project, double rate) 
    { 
     this.employee = employeeName; 
     this.project = project; 
     this.rate = rate; 
     this.hours = hours; 
    } 

    public String getEmployee() 
    { 
     return this.employee; 
    } 

    public String getProject() 
    { 
     return this.project; 
    } 

    public double getRate() 
    { 
    return this.rate; 
    } 
} 

錯誤我得到的是

error: cannot find symbol 
    this.employee = employeeName; 
       && 
    error: cannot find symbol 
    return this.employee; 

我該如何解決這個問題?

+0

你正在使用錯誤的變量。 –

回答

0
this.employee = employeeName; 

沒有實例成員在TimeCard類稱爲employee。它是employeeName

你應該寫

this.employeeName= employeeName; 
0

你可能已經從employee更新變量名employeeName

的代碼應該是this.employeeName = employeeName

0

你需要做一些改變: -

public TimeCard(String employeeName, String project, double rate) 
    { 
     this.employeeName= employeeName; // there is no such variable "employee" in your class 
     this.project = project; 
     this.rate = rate; 
     this.hours = hours; 
    } 

    public String getEmployee() 
    { 
     return this.employeeName; 
    } 
0

您已聲明vari能夠

private String employeeName; 

但是,您正在使用this.employee這是錯誤的。

您可以使用此構造如下: -

/** 
    * Constructor 1 
    */ 
    public TimeCard(String employeeName, String project, double rate) 
    { 
     //this.employee = employeeName; //this is wrong 
     this.employeeName = employeeName; 
     this.project = project; 
     this.rate = rate; 
     this.hours = hours; 
    }