Question

You are to write a program that will process employees and their pay. For each employee...

You are to write a program that will process employees and their pay. For each employee the program will read in an employee’s name and hourly pay rate. It should also read in the number of hours worked each day for 5 days and calculate his or her total number of hours worked. You must read the hours using a loop. The program should output the employee’s name, gross pay, total withholding amount and net pay. Withholding is made up of state tax, federal tax, and FICA. For the purposes of this program the state tax will be 1.25% of the gross pay. FICA will be 7.65% of the gross pay. Federal tax will be 15% of the gross pay if the gross pay is under $500 and 25% otherwise.

You do not know how many employees there are but there will be a sentinel for the employee names. The sentinel is “done”. All output should be neatly labeled with money looking like money. No global variables may be used. Information must be passed in functions. The program must have the following functions: • Read and return the employee name • Read and return the pay rate • Given the gross pay, calculate and return the total withholding amount • Display payroll information about an employee in a nice format

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code Screenshots:

Output Screenshots:

Explanation:

First create an employee class with instance variables pay-rate, name and  array of int for number of hours worked.

Then create a constructor with string and double parameters, which call setter functions of employee name , employee pay-rate and hours worked.

getGross() method will traverse over the hrs[] and increment the result with (hrs[i]*payRate) and returns the result.

getWH() method will calculate the total withHolding amount by the formula mentioned above and returns its value.

getNet() will call getGross() and getWH() and returns the difference between them.

PrintEmp() method will print all the employee details in the format with dollar symbols.

Check code for clarity:

import java.util.*;

class EMP15{

    double payrate;

    String name;

    int[] hrs = new int[5];

    EMP15(String s,double d){

        this.setName(s); this.setPR(d);

        this.readHrs();

    }

    public void setName(String nm){ this.name = nm; return;}

    public String getName(){ return this.name; }

    public void setPR(double d) {this.payrate = d; return;}

    public double getPR(){ return this.payrate; }

    public void readHrs(){

        Scanner sc = new Scanner(System.in);

        System.out.print("Enter no. of worked hours for 5 days : ");

        for(int i=0;i<5;i++){

            hrs[i] = sc.nextInt();

        }

    }

    public double getGross(){

        double grs = 0;

        for(int i=0;i<5;i++) grs = grs + (payrate*hrs[i]);

        return grs;

    }

    public double getWH(){

        double st,fc,ft,grs;

        grs = this.getGross();

        st = 0.0125*grs; fc = 0.0765*grs;

        if(grs<500) ft = 0.15*grs;

        else ft = 0.25*grs;

        return (st+fc+ft);

    }

    public double getNet(){

        return (this.getGross()-this.getWH());

    }

    public void printEmp(){

        System.out.print("\nEmployee name : "+this.name+"\n");

        System.out.print("GrossPay : $"+this.getGross()+"\n");

        System.out.print("withHolding amt : $"+this.getWH()+"\n");

        System.out.print("NetPay : $"+this.getNet()+"\n");

    }

    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);

        System.out.print("Enter 'done' insted of name when you are done..\n");

        String s; double d;

        while(true) {

            System.out.print("\nEnter name of employee and payrate : ");

            s = sc.next(); if(s.equals("done")) break;

            d = sc.nextDouble();

            EMP15 e = new EMP15(s,d);

            e.printEmp();

        }

    }

}

Add a comment
Know the answer?
Add Answer to:
You are to write a program that will process employees and their pay. For each employee...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT