# Thread: employee payroll project with inheritance and tostring

1. Member
Join Date
Jul 2015
Posts
1
Rep Power
0

## employee payroll project with inheritance and tostring

Hi, I'm kind of a novice on java and I'm trying to figure out how to use inheritance to create a employee payroll project. the problem is to create 4 class of employees (hourly, part time, salaried, and intern) inheriting from class employee.

I think I want to try and get a total number of employees so then I can integrate each one on which kind of employee they are (hourly, part time, salaried, or intern). Hourly and salaried will get 20% benefit pay on top of their pay so that's why I'd multiply by 1.2.

I will ask each employee their ID#, and the hours worked cause I'll sum up the total hours for all the employees at the end as well as the total weekly pay of all the employees.
I had to get the hourly rate from the hourly workers and part time workers.
so all this should allow me to calculate the total weekly pay for each employee and I want to list them from greatest to least.

I pieced some things together but now I'm just all confused. I would welcome any help. thanks.

import java.util.Scanner;

public abstract class Employee {
// Constructor
public Employee(String ID, String Types, double HoursWorked, double HourlyRate, double WeeklyPay) {
}
public double calcPay() {
}
}

Class HourlyEmployee extends Employee {
public HourlyEmployee(String ID, String Types, double HoursWorked, double HourlyRate, double WeeklyPay) {
Scanner in = new Scanner (System.in);
super(ID);
this.hourlyRate = hourlyRate;
}
public String toString()
{
String ID = super.toString();
return ID + " Hourly Rate: \$" + hourlyRate; }
public double calcPay() {
System. Out. Println ("How many hours did the employee work: ");
hoursWorked = in.nextDouble();
if (hoursWorked > 40)
return 1.2*(hourlyRate * 40 + hourlyRate * 1.5 * (hoursWorked - 40));
else
return 1.2*(hourlyRate * hoursWorked);
} //hourly get 20% benefits

}

class PartTimeEmployee extends Employee {
public PartTimeEmployee( String ID, double hourlyRate) {
Scanner in = new Scanner (System.in);
super(ID);
this.hourlyRate = hourlyRate;
}
public String toString()
{
String ID = super.toString();
return ID + " Hourly Rate: \$" + hourlyRate; }

public double calcPay() {

System. Out. Println ("How many hours did the employee work: ");
hoursWorked = in.nextDouble();
if (hoursWorked > 40)
return hourlyRate * 40 + hourlyRate * 1.5 * (hoursWorked - 40);
else
return hourlyRate * hoursWorked;
}
}

class InternEmployee extends Employee {

public InternEmployee( String ID, double hourlyRate) {
Scanner in = new Scanner (System.in);
super(ID);
}
public double calcPay() {
return 0;
}
class SalariedEmployee extends Employee {

public SalariedEmployee( String ID, double WeeklyPay) {
Scanner in = new Scanner (System.in);
super(ID);
this.weeklyPay= weeklyPay * 1.2;
}
public String toString();

public double calcPay() {

return weeklyPay;
}
}

public class EmployeeData{
public static void main(String[] args){
System.Out.Println ("How many employee: ");
int numberOfEmployees = in.nextInt();

for (int i = 1; i <= numberOfEmployees; i++) {
system.Out.Println( "What kind of employee is employee number " + i + "? " );
String Types= in.next();
system.Out.Println( "How many hours did employee number " + i + " work? " );
double hoursWorked = in.nextDouble();

if (kind.equals("H")) { //hourly
employees[i] = new HourlyEmployee(ID,HourlyRate); }
else if (kind.equals("P")){ //part time
employees[i] = new PartTimeEmployee(ID,HourlyRate); }
else if (kind.equals("S")){ //salaried
employees[i] = new SalariedEmployee(ID, WeeklyPay); }
else { // Intern don't get paid String [] employeeInfo = MultiInputPane.showMultiInputDialog(null, salariedLabels, "Employee Information");
employees[i] = new InterEmployee(ID,HourlyRate); }
}

//sort employee with greatest weekly pay to least weekly pay then display as table
//employee ID type (H,P,S,I) hours worked hourly rate weekly pay

}
}

2. ## Re: employee payroll project with inheritance and tostring

Please edit your post and wrap the code in code tags to preserve its formatting.

3. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
12

## Re: employee payroll project with inheritance and tostring

"I pieced some things together but now I'm just all confused. I would welcome any help. thanks."

I'm sorry to hear that, but if you can't ask for specific help then we're still at a dead end. What can anyone do so you are "less confused" ?

4. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
13

## Re: employee payroll project with inheritance and tostring

You are making trivial mistakes in your Java syntax. I must assume you have not taken the time to properly learn the language. I recommend you get 1) get a book or 2) check out some videos on learning Java. You might also try the tutorials linked in my signature.

Regards,
Jim

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•