package payroll3;
/**
*
* @author Wiccan
*/
//employee class
public class Employee {
//fields
String name;
double rate;
double hours;
double gross;
double fedtax;
double statetax;
double deduction;
double netpay;
// constructor
public Employee(String name, double rate, double hours) {
this.name = name;
this.rate = rate;
this.hours = hours;
}
//returns net pay
public double getNetPay() {
return gross - deduction;
}
public String getName() {
return name;
}
public void setName (String name) {
this.name = name;
}
public double getHours() {
return hours;
}
public void setHours(double hours) {
this.hours = hours;
}
public double getRate() {
return rate;
}
public void setRate(double rate) {
this.rate = rate;
}
public double getGross() {
return hours*rate;
}
public void setGross(double gross) {
this.gross = gross;
}
public double getFedtax() {
return fedtax*gross;
}
public void setFedtax(double fedtax){
this.fedtax = fedtax;
}
public double getStatetax() {
return statetax*gross;
}
public void setStatetax(double statetax) {
this.statetax = statetax;
}
public double getDeduction() {
return statetax+fedtax;
}
public void setDeduction (double deduction) {
this.deduction = deduction;
}
}
我基本上試圖讓該類內的變量正常工作。當我運行它的程序時,我應該得到一個淨薪金金額。然而,當我運行它時,我得到了0.00美元的數額,儘管我應該得到296.00(大約取決於輸入)。我被告知我沒有調用函數來設置值。我該如何去做?我嘗試了許多不同的方式,並認爲我做對了,但我似乎總是得到相同的輸出。調用類中的函數來設置變量
你的來電顯示代碼在哪裏? – kosa
你從哪裏設定值?並創建這個類的對象? –
調用*什麼*功能?構造函數?你打電話過得怎麼樣? – 2012-09-27 17:34:57