Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Language: Java Create an HourlyEmployee class that inherits from Employee and ha

ID: 3694433 • Letter: L

Question

Language: Java

Create an HourlyEmployee class that inherits from Employee and has two new instance variables : hours, which represents the hours worked, and wage, which represents the employee's pay per hour. (Both are doubles .) Create a constructor that takes the arguments first name , last name , social security number, hourly wage, and the number of hours worked. Also create accessors, mutators, an earnings method that returns the money earned by the employee this week, and a toString method that returns information about the employee in the form of a String . The setWage method should ensure that the wage is nonnegative, and the setHours method should ensure that the value of hours is between 0 and 168 (the number of hours in a week).

Create a Driver class with a main method that prompts the user to enter a first name , last name , social security number, hours, and wage for an employee. Then, the program should create an HourlyEmployee object and use its toString method to print information about it.

Explanation / Answer

class HourlyEmployee extends Employee

{

public:

String firstname;

String lastname;

String ssn;

double hourwage;

int hours;

double hoursworked;

public HourlyEmployee(String fname,String lname,String ssn,double hwage,double hworked)

{

this.firstname=fname;

this.lastname=lname;

this.ssn=ssn;

this.hourwage=this.hwage;

this.hoursworked=this.hworked;

}

double findEarningsWeek(Employee[] e)

{

earnings=0;

for(i=0;i<=len(employee);i++)

{

earnings+=e.hourlywage*e.hoursworked

}

return earnings;

}

void setWage(double amount)

{

if(amount>0)

this.hourlywage=amount;

}

void sethours(int hrs)

{

this.hours=hrs;

}

void toString()

{

System.out.println("First name last name ssn hourlywage hours worked ");

System.out.println(firstname+" "+lastname+" "+ssn+" "+hourlywage+" "+hoursworked);

}

}

class Test

{

public static void main(String args[])

{

System.out.println("Enter First name:");

String fname=System.in.readLine(stdin);

System.out.println("Enter Last name:");

String lname=System.in.readLine(stdin);

System.out.println("Enter SSN:");

String ssn=System.in.readLine(stdin);

System.out.println("Enter hours:");

int hrs=System.in.readLine(stdin);

System.out.println("Enter Wage:");

double wage=System.in.readLine(stdin);

e=HourlyEmployee(fname,lname,ssn,hrs,wage);

system.out.println(e);

}

}