2014-03-14 73 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; 
    }