Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Please Help - Employee Payroll Project

  1. #1
    Junior Member
    Join Date
    Oct 2017
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Please Help - Employee Payroll Project

    Hi! I'm new to Java and I'm trying to build an employee payroll system that
    1) Populate Employees
    a. You should populate one of each of the following employees in your collection:
    i. Hourly Employee
    1. Prompt for Hours
    2. Prompt for Rate
    3. Make sure to calculate for overtime at time and a half
    ii. Salary Employee
    1. Prompt for Staff or Executive
    2. Set Gross salary to $50,000 for staff and $100,000 for executives
    iii. Commission Employee
    1. Prompt for number of items sold
    2. Prompt for unit price of item sold (we are selling widgets so just set a price of your choosing)
    3. Commission Employees will get 50% of gross sales
    2) Select Employee
    a. Loop through your array and select the employee
    b. Once the employee is selected you will get a menu inside of each Employee that allows you to select the following
    i. Calculate Gross Pay
    ii. Calculate Tax
    iii. Calculate Net Pay
    iv. Calculate Net Percent
    v. Display Employee
    3) Save Employees
    a. Save the array or collection of Employees as a serialized object
    b. Additionally you will save a file/report of each employee as a text file
    4) Load Employee
    a. You will load back in the serialized objects from the saved file
    b. You should use a boolean variable that is set to true if you have loaded employees
    i. This in turn would inform users and prevent them from populating employees if they select that option

    Here is the code so far:

    public class Employee
    {
    /*********************
    Attributes
    *********************/
    float rate=30.0f;
    float taxrate=0.2f;
    int hours=45;
    float gross=0.0f;
    float tax=0.0f;
    float net=0.0f;
    float net_percent=0.0f;

    //End Attributes

    /********************
    Constructors
    ********************/
    public Employee()
    {

    }

    /********************
    Methods
    ********************/
    public void menu()
    {

    }

    public void computeGross()
    {
    gross=rate*hours;
    }

    protected void computeTax()
    {
    tax=gross*taxrate;
    }

    protected void computeNet()
    {
    net=gross-tax;
    }

    protected void computeNetperc()
    {
    net_percent=(net/gross)*100;
    }

    protected void displayEmployee()
    {
    System.out.println("Hours: " + new Integer(hours));
    System.out.println("Rate: " + new Float(rate));
    System.out.println("Gross: " + new Float(gross));
    System.out.println("Net: " + new Float(net));
    System.out.println("Net%: " + new Float(net_percent) + "%");
    }
    }

  2. #2
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    261
    My Mood
    Amused
    Thanks
    8
    Thanked 18 Times in 18 Posts

    Default Re: Please Help - Employee Payroll Project

    Hi javaNewbie2098,
    What have you tried ? Where you stuck?
    Whatever you are, be a good one

  3. #3
    Junior Member
    Join Date
    Oct 2017
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please Help - Employee Payroll Project

    Hi! So when I run Payroll.java it works up until it prints out what type of employee the user is. Now I'm trying to get it to call the calcMenu method in Employee_3 class. This is my updated Payroll.java code

    package employee_3;

    import java.io.*;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.util.*;
    /**
    *
    * @author KC
    */

    public class Payroll
    {
    static Employee_3[] employeeArray = new Employee_3[3];

    public static void main(String[] args)
    {
    Payroll sa = new Payroll();
    sa.topMenu();
    sa.saveEmployee();
    }
    private String employeeType_holdinput;

    public void topMenu()
    {
    Scanner sc = new Scanner(System.in);

    int input;
    System.out.println("1) Populate Employee");
    System.out.println("2) Select Employee");
    System.out.println("3) Save Employee");
    System.out.println("4) Load Employee");
    do
    {
    input = sc.nextInt();
    if(input == 1)
    {
    populateEmployee();
    }
    else if(input == 2)
    {
    selectEmployee();
    }
    else if(input == 3)
    {
    saveEmployee();
    }
    else
    {
    loadEmployee();
    }
    // add 5 for save_exit

    }
    while(input >= 1 && input <= 4);
    }

    public void populateEmployee()
    {
    String id_holdinput;

    Scanner sc = new Scanner(System.in);

    System.out.println("Please enter what type of employee you are:"
    + " C-Commission, H-Hourly S-Salary");

    for(int i=0; i<1; i++)
    {
    String input = sc.next();
    if(input.equalsIgnoreCase("S"))
    {
    System.out.println("You are a SALARY employee.");
    employeeArray[0].calcMenu();
    }
    else if(input.equalsIgnoreCase("H"))
    {
    System.out.println("You are an HOURLY employee.");
    employeeArray[1].calcMenu();
    }
    else if(input.equalsIgnoreCase("C"))
    {
    System.out.println("You are a COMMISSION employee.");
    employeeArray[2].calcMenu();
    }
    else
    {
    System.out.println("Error.");
    }
    }

    }
    public void selectEmployee()
    {
    float ex1_holdinput;
    Scanner sc = new Scanner(System.in);

    System.out.println("Please enter your name so we can look you up:");
    String secondinput = sc.next();
    int index = -1;
    for(int i = 0; i < employeeArray.length; i++)
    {

    if(employeeArray[i].getName().equalsIgnoreCase(secondinput))
    {
    index = i;
    }
    }

    System.out.print("Enter Employee Type: ");
    employeeType_holdinput = sc.next();
    // was nextFloat ?
    if(index == -1)
    {
    System.out.println("We didn't find your employee record,"
    + " please contact system administrator");
    }
    else
    {
    employeeArray[index].setName(employeeType_holdinput);
    employeeArray[index].displayEmployee();
    }
    }

    public void saveEmployee()
    {
    try
    {
    FileOutputStream fos = new FileOutputStream("EmployeeData.txt");
    ObjectOutputStream oos = new ObjectOutputStream(fos);

    oos.writeObject(employeeArray);
    oos.flush();
    fos.close();
    }
    catch (IOException e)
    {
    System.err.println(e);
    }
    }

    public void loadEmployee()
    {
    try
    {
    FileInputStream fis = new FileInputStream("EmployeeData.txt");
    ObjectInputStream ois = new ObjectInputStream(fis);
    employeeArray = (Employee_3[])ois.readObject();
    fis.close();
    for(int i = 0; i < employeeArray.length; i++)
    {
    employeeArray[i].displayEmployee();
    }
    }
    catch (IOException e)
    {
    System.err.println("An error was encounter please try again.");
    topMenu();
    }
    catch( ClassNotFoundException cnfe)
    {
    System.err.println("File to load accounts was not found.");
    topMenu();
    }
    }

    private void writeNewEmployeeData()
    {
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    private void computeGross()
    {
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    private void computeTax()
    {
    throw new UnsupportedOperationException("Not supported yet.");
    }

    private void computeNet()
    {
    throw new UnsupportedOperationException("Not supported yet.");
    }

    private void computeNetperc()
    {
    throw new UnsupportedOperationException("Not supported yet.");
    }

    private void displayEmployee()
    {
    throw new UnsupportedOperationException("Not supported yet.");
    }

    }// end class Payroll

  4. #4
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    261
    My Mood
    Amused
    Thanks
    8
    Thanked 18 Times in 18 Posts

    Default Re: Please Help - Employee Payroll Project

    Why you need array to call method ?
     static Employee_3[] employeeArray = new Employee_3[3];

    And show your Employee_3 class
    Last edited by John Joe; October 19th, 2017 at 08:35 PM.
    Whatever you are, be a good one

  5. #5
    Junior Member
    Join Date
    Oct 2017
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please Help - Employee Payroll Project

    Quote Originally Posted by John Joe View Post
    Why you need array to call method ?
     static Employee_3[] employeeArray = new Employee_3[3];

    And show your Employee_3 class
    This is the Employee_3 class:

    package employee_3;

    import java.io.Serializable;
    import java.util.Scanner;

    /**
    *
    * @author KC
    */
    public class Employee_3 implements Serializable
    {
    private String Name;
    public float employeeType;
    //

    public static int counter;

    // added variables
    float rate=30.0f;
    float taxrate=0.2f;
    int hours=45;
    float gross=0.0f;
    float tax=0.0f;
    float net=0.0f;
    float net_percent=0.0f;

    public Employee_3() //constructor
    {
    }

    public String getName()
    {
    return Name;
    }

    public void setName(String s)
    {
    Name = new String(s);
    }

    public void setemployeeType(float et)
    {
    employeeType = et;
    }

    public void computeGross()
    {
    gross = rate * hours;
    }

    protected void computeTax()
    {
    tax = gross * taxrate;
    }

    protected void computeNet()
    {
    net = gross - tax;
    }

    protected void computeNetperc()
    {
    net_percent = ( net / gross )* 100;
    }

    // employee calculations

    public void calcMenu()
    {
    Scanner sc = new Scanner(System.in);
    int input;
    System.out.println("Please enter your id [first name and last initial]: ");
    Name = sc.next();

    do
    {
    System.out.println("0) Calculate Gross");
    System.out.println("1) Calculate Tax");
    System.out.println("2) Calculate Net");
    System.out.println("3) Calculate Net Percent");
    System.out.println("4) Display Employee");

    input = sc.nextInt();
    if(input == 0)
    {
    computeGross();
    }
    else if(input == 1)
    {
    computeTax();
    }
    else if(input == 2)
    {
    computeNet();
    }
    else if(input == 3)
    {
    computeNetperc();
    }
    else
    {
    displayEmployee();
    }
    }
    while(input >= 0 && input <= 4);

    }

    protected void displayEmployee()
    {
    System.out.println("Name: " + Name);
    System.out.println("Hours: " + hours);
    System.out.println("Rate: " + rate);
    System.out.println("Gross: " + gross);
    System.out.println("Net: " + net);
    System.out.println("Net%: " + net_percent + "%");
    }
    }

    //} // end class Employee_3

    --- Update ---

    Quote Originally Posted by John Joe View Post
    Why you need array to call method ?
     static Employee_3[] employeeArray = new Employee_3[3];

    And show your Employee_3 class
    It was suggested that I use an array

Similar Threads

  1. employee management project in an education instituition
    By dichu in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 26th, 2014, 04:37 AM
  2. [SOLVED] Payroll assignment
    By ggx7 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 27th, 2014, 01:49 AM
  3. Someone who can help me with my PAYROLL PROGRAM
    By driczdc in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 5th, 2013, 05:02 AM
  4. employe payroll
    By daim9996 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 18th, 2013, 08:35 AM
  5. Payroll
    By Kesh486 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 6th, 2010, 06:48 PM