我正在爲班級任務編寫員工,經理,小時工的代碼,但是我遇到了一個我無法弄清楚的問題,以下是我的員工代碼,然後是小時工。問題是小時工不會編譯,它會給我一個「找不到符號構造函數員工」的錯誤,當我嘗試編譯時(員工類compiiles沒有問題,任何建議請嗎?我想我一直在盯着它很久我再也看不到問題的感謝彼得Java編譯器錯誤:「找不到符號構造函數..」?
Employee類 - !。
public class Employee
{
public String firstName;
public String lastName;
public double hourlyRate;
final static double NORMAL_WORKWEEK = 37.5;
public Employee(String firstName, String lastName, double hourlyRate)
{
setFirstName(firstName);
setLastName(lastName);
setHourlyRate(hourlyRate);
}
//Accessor and Mutator Methods for the employee's first name.
public String getFirstName()
{
return firstName;
}
public void setFirstName(String firstName)
{
firstName = firstName;
}
//Accessor and Mutator Methods for the employee's last name.
public String getLastName()
{
return lastName;
}
public void setLastName(String lastName)
{
lastName = lastName;
}
//Access and Mutator Methods for the employee's hourly rate.
public double getHourlyRate()
{
return hourlyRate;
}
public void setHourlyRate(double hourlyRate)
{
//If the user input is valid, update the employee's hour rate with the newly input value.
if(hourlyRate > 0)
{
hourlyRate = hourlyRate;
}
//Otherwise prevent an hour rate greater than zero being overwritten
else if(hourlyRate <=0)
{
if(hourlyRate <= 0)
{
hourlyRate = 0;
}
decorateConsole();
//Alert the user to their mistake.
System.out.println("Error ! ! ! - An attempt to set the employee " + this.firstName + " " + this.lastName + "'s hourly rate to zero was detected.\n");
decorateConsole();
}
}
public void printState()
{
decorateConsole();
System.out.println("[FIRST NAME] = " + firstName + " [LAST NAME] = " + lastName + " [HOURLY RATE] = " + hourlyRate + "\n");
decorateConsole();
}
public void decorateConsole()
{
System.out.println("+-< EMPLOYEE INFO >-------------------------------------------------------------------------------------------------------------------------+\n");
}
小時工CLASS -
public class HourlyWorker extends Employee
{
private double wage;
private double hours;
public HourlyWorker(String firstName, String lastName, double hourlyWage, double hoursWorked)
{
super(firstName, lastName);
this.wage = wage;
this.hours = hours;
}
public void setWage (double hourlyWage)
{
this.wage = wage;
}
public void getWage()
{
return wage;
}
public void setHours (double hours)
{
this.hours = hours;
}
public double getHours()
{
return hours;
}
}
你的編譯命令是什麼? – dacwe 2010-11-30 21:47:18
我建議你下次粘貼錯誤代碼,這樣更容易發現錯誤。 – OscarRyz 2010-11-30 21:47:51
你的二傳手破碎了。 `firstName = firstName` - 將`firstName`(局部變量)的值賦給局部變量`firstName`(即它覆蓋自身)。你應該寫`this.firstName = firstName`。 – Crozin 2010-11-30 22:25:22