hi this is another one of my practicing program. One called personnel, there are three classes. one is hourlywage employee, salaredemployee and employess(which is abstract) along with my main class called personnel: i am going to put all three classes along with my main for you all to take a look at them and i am also going to post the end result. (how it supposed to run and the result that I am looking for. the first class will be the employee class. this is what the employees class should do. I cant figure out to get a method to increase the hourly wage by percentage , an abstract method called computePay that calculate the weekly pay for the employee. here is the employee class
that is the employee class above.
the next class is the hourlywage employees class which extends the employee class. I think there is some pretty much calculation still to be done but dont know if what I have is correct. check it for me plz. here. here is what the hourlywage class supposed to do in respect in calculation; Methods will include computePay and toString. To determine the employee’s pay, computePay mulitplies the first 40 hours (or ferwer) by the employee’s hourly wage. Hours worked beyond 40 are paid at time-and-a-half (1.5 times the hourly wage). toString returns a string containing the employee’s name and hourly wage, formatted as shown in the example of the r command.
here is the hourlywage class
this is the salariedemployee class which is also an extension to employee class: To do this conversion, assume that a salaried employee works a 40 hours a week for 52 weeks.) comptePay always returns 1/52 of the annual salary, regardless of the number of hours worked. toString returns a string containing the employee’s name and annual salary, formatted as shown in the example of the r command.
here is the salaried employee class
and last but not least here is the main, it is called personnel: in the main, i am trying to bring up a method called equals. using the while loop. trying to quite the program using the while loop but not getting it to come up. the while loop supposed to be like this: while(!choice.equals("q") for some reason cant get it. here is the main class
this is the while loop am trying to use
will post the result that I am looking for when i hear from u
public abstract class Employee { String firstname; String lastname; double hourlywage; float rate; double pay; int extrahours; double wagepercentage; boolean wage; public Employee(String firstname, String lastname, double hourlywage){ this.firstname = firstname; this.lastname = lastname; setWage(hourlywage); } public abstract double comPay(double hours);{ pay=(40 * rate)+ (extrahours * rate + 1.5); } public String getfirstname(){ return firstname; } public String getlastname(){ return lastname; } public double gethourlywage(){ return hourlywage; } public void setfirstname(String firstname){ this.firstname = firstname; } public void setlastname(String lastname){ this.lastname = lastname; } public void setWage(double hourlywage) { wage = (hourlywage < 0.0) && (hourlywage <= 1.5); } public void wagepercentage(double percentage){ wagepercentage = wagepercentage * ((100 + percentage)/100); } @Override public String toString(){ return "Employee details "+"\n"+ "Employee firstname is"+ firstname+"\n"+"Employee last name is: "+"" + "Hourly wage is "+hourlywage; }
public class HourlyEmployee extends Employee { String firstname; String lastname; float rate; double comPay; double hourlyWage; double totalpay=0; double wage; double hours; double raiseWage; double percent; public HourlyEmployee(String firstname, String lastname, double hourlywage) { super(firstname, lastname, hourlywage); setWage(hourlyWage); } public double comPay(){ return 0; } public String getfirstname(){ return firstname; } public String getlastname(){ return lastname; } public double raiseWage(){ return raiseWage; } public double gethourlywage(){ return hourlywage; } public void setfirstname(String firstname){ this.firstname = firstname; } public void setlastname(String lastname){ this.lastname = lastname; } public void sethourlywage(double hourlywage){ this.hourlywage = hourlywage; } public double getWage(){ return wage; } public void setWage(double hourlyWage) { } public double getHours() { return hours; } public void setHours(double hoursWorked){ hours = hoursWorked; } public void setraiseWage(double percent){ wage = wage *((100 + percent)/ 100); } public double earnings(){ if(getHours()<=40) return getWage()* getHours(); return 40 * getWage() + (getHours() - 40 * getWage() * 1.5); } @Override public String toString(){ return "Employees details"+ " "+ "First name is "+ firstname+""+"Hourlywage is "+hourlywage; } @Override public double comPay(double hours) { return 0; } }
public class SalariedEmployee extends Employee { String firstname; String lastname; double annualsalary; double comPay; int hours; public SalariedEmployee(String firstname,String lastname, double annualsalary){ super(firstname, lastname, annualsalary); annualsalary = this.annualsalary; } public String getfirstname(){ return firstname; } public String getlastname(){ return lastname; } public double getannualsalary(){ return annualsalary; } public void setfirstname(String firstname){ this.firstname = firstname; } public void setlastname(String lastname){ this.lastname = lastname; } public void setannualsalary(double annualsalary){ this.annualsalary = annualsalary; } @Override public double comPay(double hours) { if(hours > 40){ double extrahours = hours - 40; pay = (40 * rate) + (extrahours * rate); } else{ pay = hours * rate; } return annualsalary; } public String toString(){ return "Salaried Employee "+"\n"+"Employee name is"+firstname+"\n"+"Annual Salaried is"+ annualsalary; }
ublic class Personnel { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner scanin = new Scanner(System.in); String firstname, lastname; double hourlywage; char command = 0; String n,p,r, s,h; double annualsalary, new_wage; double hoursworked; double hourly =0, salaried=0; float percentinc; boolean choice = true; Employee[] newemp = new Employee[50]; while(command != 'q'){ System.out.print("Please select one of the following option"); System.out.print("n - Select new employee"); System.out.print("p - To compute paychecks"); System.out.print("r - For raise wages"); System.out.print("q - To quit"); if(command == 'n'){ System.out.print("Enter new employee name"); firstname = scanin.next(); System.out.print("Enter new employee last name"); lastname = scanin.next(); }else if(hourly == 'h' || salaried == 's'){ System.out.print("Enter number of hourly wage"); }else if(command == 'n'){ System.out.print("Enter new employee name"); firstname = scanin.next(); System.out.print("Enter last name"); lastname = scanin.next(); }else if(hourly == 'h' || salaried == 's'){ System.out.print("Enter annual salary"); annualsalary = scanin.nextDouble(); } break; } if(command == 'p'){ System.out.print("Enter number of hours worked"); hoursworked = scanin.nextDouble(); }else if(command == 'r'){ System.out.print("Enter percentage increase"); percentinc = scanin.nextFloat(); } else{ System.out.print("Enter new wages"); new_wage = scanin.nextDouble(); } while(!choice.){ } } }
while(!choice.equals("q")){ System.out.println("Enter a number or q to quit"); choice = input.next(); if(!choice.equals("q")){ int number = Integer.parseInt(choice); } }