编写一个java getBonusPercentage()方法,返回员工的奖金加工资
对于完成下面的 Java 课程的任何帮助,我们将不胜感激 -
永久雇员按固定小时费率支付。 他们也可能有资格获得奖金,也可能没有资格 -
如果他们没有资格,那么他们的奖金百分比应设置为 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();
}
}
Any assistance in completing the Java class below would be much appreciated -
Permanent employee paid by the hour at a fixed hourly rate.
They also may or may not qualify for a bonus -
if they don't qualify then their bonus percentage should be set to 0
if they do qualify their bonus must be greater than zero but lest than 5
if an incorrect value for the percentage is entered the percentage should be set to zero and a an error message printed.
The bonus is calculated on their salary and added to it.
Here's what I have so far (extended from an employee superclass) -
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();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要做的(我相信)是根据您拨打超级电话时的奖金设置每小时费率。
此调用根据奖金调整每小时费率。该调用有点难看,因为需要检查 PermanentEmployeeBonus 的错误输入。
如果(在构造之后)调用
setPermanentEmployeeBonus
,就会出现问题。如何将该信息传递给基类?在基类中创建一个setHourlyRate
并在调用setPermanentEmployeeBonus
时更改它。You need to do (I believe) is set the hourly rate based on the bonus in your call to super.
This call adjusts the hourlyrate based on the bonus. The call is a little ugly because there is a check for a bad input to PermanentEmployeeBonus.
A problem occurs if (after construction) you call the
setPermanentEmployeeBonus
. How do you get that information to the base class? Create asetHourlyRate
in the base class and change it when you callsetPermanentEmployeeBonus
.最明显的问题是您没有检查上限 5。除此之外,还不清楚您希望它做什么而它没有做什么。具体一点——您对这段代码进行了什么调用,您得到了什么结果,以及您期望得到什么结果?
从您的“规范”中尚不清楚您想要在设置奖金百分比后如何处理它。正如斯塔基所描述的,一种选择是提高小时费率以包含奖金。在真实的系统中,这对我来说似乎不合理,但也许这是您应该做的事情(我猜这是家庭作业)。
我预计更现实的实施将有一个步骤,计算一段时间内的总工资,这将用小时数乘以每小时工资,然后将总数增加到奖金百分比。但同样,从您的规范中并不清楚您想要做什么。
The most obvious issue is that you are not checking against the upper limit of 5. Aside from that, it's not clear what you want it to do that it's not doing. Be specific -- what call are you making to this code, what results are you getting, and what results to you expect to get?
It's unclear from your "spec" what you want to do with the bonus percentage once it is set. One option, as described by Starkey, is to increase the hourly rate to include the bonus. This doesn't seem sensible to me in a real system, but maybe it is what you are expected to do (I'm guessing this is homework).
I would expect a more real-world implementation would have a step of calculating a total salary for some time period, which would multiply hours by hourly rate, then increase the total by the bonus percentage. But again, it's not clear from your spec what you want to do.