开发者

Write a java getBonusPercentage() method to return an employee's bonus plus salary

开发者 https://www.devze.com 2023-01-28 13:09 出处:网络
Any assistance in completing the Java class below would be much appreciated - Permanent employee paid by the hour at a fixed hourly rate.

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.

开发者_如何学Python

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();

 }


}


You need to do (I believe) is set the hourly rate based on the bonus in your call to super.

super(firstname, lastname, (hourlyrate * (1 + ((PermanentEmployeeBonus<0) ? 0 : PermanentEmployeeBonus)/100.0)));

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 a setHourlyRate in the base class and change it when you call setPermanentEmployeeBonus.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消