在填寫下面的Java類的任何援助將不勝感激 -編寫Java getBonusPercentage()方法返回一個僱員的獎金加工資
在一個固定的每小時收費按小時收費永久員工。 他們還可能會或可能不會有資格獲得獎金 -
,如果他們沒有資格那麼他們的獎金比例應設置爲0 如果他們不符合他們的獎金必須大於零,但恐怕比5 如果輸入的百分比值不正確,應將百分比設置爲零,並打印錯誤消息。 獎金是根據他們的薪水計算並添加到其中。
這是我迄今(延伸從僱員超) -
public class PermanentEmployee extends Employee
{
private double PermanentEmployeeBonus;
public PermanentEmployee(String firstName, String lastName, double hourlyRate, double PermanentEmployeeBonus)
{
super(firstName, lastName, hourlyRate);
setPermanentEmployeeBonus(PermanentEmployeeBonus);
}
public double getPermanentEmployeeBonus()
{
return PermanentEmployeeBonus;
}
public void setPermanentEmployeeBonus(double PermanentEmployeeBonus)
{
//If the user input is valid, update the managerial bonus with the newly inputted value.
if(PermanentEmployeeBonus > 0)
{
this.PermanentEmployeeBonus = PermanentEmployeeBonus;
}
//Otherwise prevent a managerial bonus greater than zero being overwritten
else if(PermanentEmployeeBonus <= 0)
{
if(PermanentEmployeeBonus <= 0)
{
this.PermanentEmployeeBonus = 0;
}
super.decorateConsole();
//Alert the user to their mistake.
System.out.println("Error ! ! ! - An attempt to set the employee " + super.getFirstName() + " " + super.getLastName() + "'s permanent employee bonus to zero was detected.\n");
super.decorateConsole();
}
}
public void printState()
{
super.printState();
System.out.println("[PERMANENT EMPLOYEE BONUS] for " +super.getFirstName() + " " + super.getLastName() + " = " + PermanentEmployeeBonus + "\n");
super.decorateConsole();
}
}
好的,有什麼問題?該代碼似乎幾乎是正確的。 – 2010-12-01 12:27:26