CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2002
    Location
    chickamauga, ga
    Posts
    2

    Unhappy HELP with NETPAYROLL!!!

    wite a java program that will compute an employee's net pay.you will have the following 1) Employee class(external) 2) Boss Class(external) 3) CommissionWorker(external) 4) PieceWorker Class (external) 5) HourlyWorker Class(external) 6) NetPayrollTest Class(driver)

    add private instance variables birthdate, deduction rate, and social security number to Class Employee
    Assume this payroll is proccessed once per month. then, as your program calculates the payroll for each Employee(polymorphically)add $100.00 bonus to the person's payroll gross amount if it is the month in which the employee's birthday occurs.

    The Employee class will contain a private static variables for counting the number of employees and
    the total net payroll amount; also static methods used to obtain the current number of employees and the net payroll amount.

    The NetPayrollTest application program will send to the external class/es via instantiation all the information each employee have ss3, and birthdate as part of their data. All employee's have a standard deduction of 22.5%
    Within the program demonstrate the try/catch logic all classes packaged as follows except the NetPayrollTest which will be in the root: CIS2421/Programs/Assignment

    note: all source files will be created in the root dir. and when compiled the class file/s will be directed to the respective package. NetPayrollTest will be compiled an run from the root dir.


    I need help bad this is what I have so far
    // Employee.java
    // Abstract base class Employee.

    public abstract class Employee {
    private String firstName;
    private String lastName;
    private String ssNumber;
    private String birthDate;
    private Date birthDate;

    // constructor
    public Employee( String first, String last, String ss, int birthMonth, int birthDay, int birthYear, )
    {
    firstName = first;
    lastName = last;
    ssNumber = ss;
    birthDate = new Date( birthMonth, birthDay, birthYear );
    }

    // get first name
    public String getFirstName()
    {
    return firstName;
    }

    // get last name
    public String getLastName()
    {
    return lastName;
    }

    //get social security Number
    public String getssNumber()
    {
    return ssNumber;
    }

    // get birthday
    public String getbirthDate()
    {
    return birthDate;
    }

    public String toString()
    {
    return firstName + ' ' + lastName + ' ' + ssNumber + ' ' + " Birthday: " + birthDate.toString();;
    }

    // Abstract method that must be implemented for each
    // derived class of Employee from which objects
    // are instantiated.
    public abstract double earnings();

    } // end class Employee
    // Boss.java
    // Boss class derived from Employee.

    public final class Boss extends Employee {
    private double monthlySalary;

    // constructor for class Boss
    public Boss( String first, String last, String ss, String birth, double salary )
    {
    super( first, last, ss, birth ); // call superclass constructor
    setMonthlySalary( salary );
    }

    // set Boss's salary
    public void setMonthlySalary( double salary )
    {
    monthlySalary = ( salary > 0 ? salary : 0 );
    }

    // get Boss's pay
    public double earnings()
    {
    return monthlySalary-22.5;
    }

    // get String representation of Boss's name
    public String toString()
    {
    return "Boss: " + super.toString();
    }

    } // end class Boss

    // HourlyWorker.java
    // Definition of class HourlyWorker

    public final class HourlyWorker extends Employee {
    private double wage; // wage per hour
    private double hours; // hours worked for week

    // constructor for class HourlyWorker
    public HourlyWorker( String first, String last, String ss, String birth,
    double wagePerHour, double hoursWorked )
    {
    super( first, last, ss, birth ); // call superclass constructor
    setWage( wagePerHour );
    setHours( hoursWorked );
    }

    // Set the wage
    public void setWage( double wagePerHour )
    {
    wage = ( wagePerHour > 0 ? wagePerHour : 0 );
    }

    // Set the hours worked
    public void setHours( double hoursWorked )
    {
    hours = ( hoursWorked >= 0 && hoursWorked < 168 ?
    hoursWorked : 0 );
    }

    // Get the HourlyWorker's pay
    public double earnings() { return wage * hours/22.5; }

    public String toString()
    {
    return "Hourly worker: " + super.toString();
    }

    } // end class HourlyWorker

    //PieceWorker.java
    // PieceWorker class derived from Employee

    public final class PieceWorker extends Employee {
    private double wagePerPiece; // wage per piece output
    private int quantity; // output for week

    // constructor for class PieceWorker
    public PieceWorker( String first, String last, String ss, String birth,
    double wage, int numberOfItems )
    {
    super( first, last, ss, birth ); // call superclass constructor
    setWage( wage );
    setQuantity( numberOfItems );
    }

    // set PieceWorker's wage
    public void setWage( double wage )
    {
    wagePerPiece = ( wage > 0 ? wage : 0 );
    }

    // set number of items output
    public void setQuantity( int numberOfItems )
    {
    quantity = ( numberOfItems > 0 ? numberOfItems : 0 );
    }

    // determine PieceWorker's earnings
    public double earnings()
    {
    return quantity * wagePerPiece/22.5;
    }

    public String toString()
    {
    return "Piece worker: " + super.toString();
    }

    } // end class PieceWorker

    // CommissionWorker.java
    // CommissionWorker class derived from Employee

    public final class CommissionWorker extends Employee {
    private double salary; // base salary per week
    private double commission; // amount per item sold
    private int quantity; // total items sold for week

    // constructor for class CommissionWorker
    public CommissionWorker( String first, String last, String ss, String birth,
    double salary, double commission, int quantity )
    {
    super( first, last, ss, birth ); // call superclass constructor
    setSalary( salary );
    setCommission( commission );
    setQuantity( quantity );
    }

    // set CommissionWorker's monthly base salary
    public void setSalary( double monthlySalary )
    {
    salary = ( monthlySalary > 0 ? monthlySalary : 0 );
    }

    // set CommissionWorker's commission
    public void setCommission( double itemCommission )
    {
    commission = ( itemCommission > 0 ? itemCommission : 0 );
    }

    // set CommissionWorker's quantity sold
    public void setQuantity( int totalSold )
    {
    quantity = ( totalSold > 0 ? totalSold : 0 );
    }

    // determine CommissionWorker's earnings
    public double earnings()
    {
    return salary + commission * quantity/22.5;
    }

    // get String representation of CommissionWorker's name
    public String toString()
    {
    return "Commission worker: " + super.toString();
    }

    } // end class CommissionWorker

    //Test.java
    // Driver for Employee hierarchy

    // Java core packages

    import java.text.DecimalFormat;

    // Java extension packages
    import javax.swing.JOptionPane;

    public class Test {

    // test Employee hierarchy
    public static void main( String args[] )
    {
    Employee employee; // superclass reference
    String output = "";

    Boss boss = new Boss( "John", "Smith", "SS#-456-47-1234", "BirthDay-5-26-71", 800.0 );

    CommissionWorker commissionWorker =
    new CommissionWorker(
    "Sue", "Jones", "458-63-5454", "3-14 -45", 400.0, 3.0, 150 );

    PieceWorker pieceWorker =
    new PieceWorker( "Bob", "Lewis", "123-34-5678", "1-2-70", 2.5, 200 );

    HourlyWorker hourlyWorker =
    new HourlyWorker( "Karen", "Price","234-56-7890", "2-3-69", 13.75, 40 );

    DecimalFormat precision2 = new DecimalFormat( "0.00" );

    // Employee reference to a Boss
    employee = boss;

    output += employee.toString() + " earned $" +
    precision2.format( employee.earnings() ) + "\n" +
    boss.toString() + " earned $" +
    precision2.format( boss.earnings() ) + "\n";

    // Employee reference to a CommissionWorker
    employee = commissionWorker;

    output += employee.toString() + " earned $" +
    precision2.format( employee.earnings() ) + "\n" +
    commissionWorker.toString() + " earned $" +
    precision2.format(
    commissionWorker.earnings() ) + "\n";

    // Employee reference to a PieceWorker
    employee = pieceWorker;

    output += employee.toString() + " earned $" +
    precision2.format( employee.earnings() ) + "\n" +
    pieceWorker.toString() + " earned $" +
    precision2.format( pieceWorker.earnings() ) + "\n";

    // Employee reference to an HourlyWorker
    employee = hourlyWorker;

    output += employee.toString() + " earned $" +
    precision2.format( employee.earnings() ) + "\n" +
    hourlyWorker.toString() + " earned $" +
    precision2.format( hourlyWorker.earnings() ) + "\n";

    JOptionPane.showMessageDialog( null, output,
    "Demonstrating Polymorphism",
    JOptionPane.INFORMATION_MESSAGE );

    System.exit( 0 );
    }

    } // end class Test


    HELP!!PLEASE!!! I'm lost and confussed

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163
    Perhaps if you asked a specific question, someone might be able to answer it...
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    Dec 2002
    Location
    chickamauga, ga
    Posts
    2
    what I want to know is if my code is going in the right direction or do I need to start from scratch

  4. #4
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163
    what I want to know is if my code is going in the right direction or do I need to start from scratch
    Does it work? Does it fit the requirement?

    From what I could make out (it would help a lot if it was formatted - doesn't anyone read the submission guidelines?) it looks OK, but I didn't see any try...catch code, and they are probably expecting you to process each employee object with the same piece of code to demonstrate polymorphism. You might try adding each employee object to an array or container as it is created, then iterating through the container (possibly after passing it to another method?) retrieving the employee objects and outputting their details.
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured