Write a java getBonusPercentage() method to return an employee's bonus plus salary -
any assistance in completing java class below appreciated -
permanent employee paid hour @ fixed hourly rate. may or may not qualify bonus -
if don't qualify bonus percentage should set 0 if qualify bonus must greater 0 lest 5 if incorrect value percentage entered percentage should set 0 , error message printed. bonus calculated on salary , added it.
here's have far (extended 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 user input valid, update managerial bonus newly inputted value. if(permanentemployeebonus > 0) { this.permanentemployeebonus = permanentemployeebonus; } //otherwise prevent managerial bonus greater 0 being overwritten else if(permanentemployeebonus <= 0) { if(permanentemployeebonus <= 0) { this.permanentemployeebonus = 0; } super.decorateconsole(); //alert user mistake. system.out.println("error ! ! ! - attempt set employee " + super.getfirstname() + " " + super.getlastname() + "'s permanent employee bonus 0 detected.\n"); super.decorateconsole(); } } public void printstate() { super.printstate(); system.out.println("[permanent employee bonus] " +super.getfirstname() + " " + super.getlastname() + " = " + permanentemployeebonus + "\n"); super.decorateconsole(); } }
you need (i believe) set hourly rate based on bonus in call super.
super(firstname, lastname, (hourlyrate * (1 + ((permanentemployeebonus<0) ? 0 : permanentemployeebonus)/100.0)));
this call adjusts hourlyrate based on bonus. call little ugly because there check bad input permanentemployeebonus.
a problem occurs if (after construction) call setpermanentemployeebonus
. how information base class? create sethourlyrate
in base class , change when call setpermanentemployeebonus
.
Comments
Post a Comment