如何在下面的toString方法中使用qualifiedForBonus()的输出。我使用“this.isBonus”作为占位符,但它不起作用,因为isBonus不是该类中的变量。
public String eligibleForBonus(double salary){
String isBonus;
if (salary >= 40000) {
isBonus = "is";
}
else {
isBonus = "is not";
}
return isBonus;
}
}
@Override
public String toString() {
return this.forename + " " + this.surname + " (" + this.id + "): " + this.companyPosition + " at " + this.salary + " and " + this.isBonus + " eligible for bonus.";
}
答案 0 :(得分:3)
正如Rohit所说,只需调用方法来获得回报:
return this.forename + " " + this.surname + " (" + this.id + "): " + this.companyPosition + " at " + this.salary + " and " + this.eligibleForBonus(this.salary) + " eligible for bonus.";
一些意见: