Results 1 to 4 of 4
  1. #1
    yuechu is offline Member
    Join Date
    Jul 2015
    Posts
    1
    Rep Power
    0

    Default 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. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: employee payroll project with inheritance and tostring

    Please edit your post and wrap the code in code tags to preserve its formatting.
    If you don't understand my response, don't ignore it, ask a question.

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

    Default 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" ?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

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

    Default 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
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Jsp Project on Employee Details
    By 82rathi.angara in forum JavaServer Pages (JSP) and JSTL
    Replies: 8
    Last Post: 01-20-2014, 09:34 AM
  2. Replies: 6
    Last Post: 02-11-2013, 05:22 AM
  3. Payroll Project 1 Troubles
    By KiskaBaker in forum New To Java
    Replies: 3
    Last Post: 08-16-2009, 12:41 PM
  4. help for payroll project in java
    By mageshwari in forum New To Java
    Replies: 2
    Last Post: 04-09-2008, 02:46 AM
  5. Inheritance, methods, and toString...
    By Kreuz14 in forum New To Java
    Replies: 1
    Last Post: 04-01-2008, 10:12 PM

Posting Permissions

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