Two Sample Run:Enter emplovee's name: SmithEnter number of hours worked in a week: 10Enter hourly pay rate: 9.75Enter federal tax withholding rate: 0.2Enter state tax withholding rate: 0.09Enter employee's name: JohnEnter number of hours worked in a week: 40Enter hourly pay rate: 12.50Enter federal tax withholding rate: 0.15Enter state tax withholding rate: 0.08Employee Name: SmithHours Worked 10.00Pay Rate: $9.75Gross Pay: $97.50Deductions:Employee Name: JohnHours Worked: 40.00Pay Rate: $12.50Gross Pay: $500.00Deductions:Federal withholding (20.00%): $19.50state withholding (9.00%): $8.78Total Deduction: $28.28Federal withholding (15.00%): $75.00state withholding (8.00%); $48.00Total Deduction: $115.00Net Pay: $69.23Net Pay: $385.00

Question
Asked Mar 24, 2019
71 views

For this program you need to use Eclipse.

Carefully read the instructions and write a program that reads the following
information and prints a payroll statement.
Employee’s name (e.g., Smith)
Number of hours worked in a week (e.g., 10)
Hourly pay rate (e.g., 9.75)
Federal tax withholding rate (e.g., 20%)
State tax withholding rate (e.g., 9%)

design a program to
• Prompt user for 5 values and read the values using Scanner
o Use method .nextLine() to get the String for the name
o Use method .nextDouble() to get all other numeric values
• Calculating the Gross pay
o Gross pay = hours worked * hourly pay rate
• Calculating the Federal withholding
o Federal withholding = Gross pay * federal tax withholding rate
• Calculating the State withholding
o State withholding = Gross pay * state tax withholding rate
• Calculating the Total deduction
o Total deduction = Federal withholding + State withholding
• Calculating the Net Pay
o Net Pay = Gross pay – Total deduction
• Formatting the output same as the Sample run (Use ONLY printf)
o Correctly format 2 decimals and use $ (hint $%.2f)
o Indenting the under Deductions (hint \t)
o Printing % for state withholding and federal withholding rate (hint refer to
practice question below)

Include a comment at the start of the program with the following.

The computer must do all calculations.

Two Sample Run:
Enter emplovee's name: Smith
Enter number of hours worked in a week: 10
Enter hourly pay rate: 9.75
Enter federal tax withholding rate: 0.2
Enter state tax withholding rate: 0.09
Enter employee's name: John
Enter number of hours worked in a week: 40
Enter hourly pay rate: 12.50
Enter federal tax withholding rate: 0.15
Enter state tax withholding rate: 0.08
Employee Name: Smith
Hours Worked 10.00
Pay Rate: $9.75
Gross Pay: $97.50
Deductions:
Employee Name: John
Hours Worked: 40.00
Pay Rate: $12.50
Gross Pay: $500.00
Deductions:
Federal withholding (20.00%): $19.50
state withholding (9.00%): $8.78
Total Deduction: $28.28
Federal withholding (15.00%): $75.00
state withholding (8.00%); $48.00
Total Deduction: $115.00
Net Pay: $69.23
Net Pay: $385.00
help_outline

Image Transcriptionclose

Two Sample Run: Enter emplovee's name: Smith Enter number of hours worked in a week: 10 Enter hourly pay rate: 9.75 Enter federal tax withholding rate: 0.2 Enter state tax withholding rate: 0.09 Enter employee's name: John Enter number of hours worked in a week: 40 Enter hourly pay rate: 12.50 Enter federal tax withholding rate: 0.15 Enter state tax withholding rate: 0.08 Employee Name: Smith Hours Worked 10.00 Pay Rate: $9.75 Gross Pay: $97.50 Deductions: Employee Name: John Hours Worked: 40.00 Pay Rate: $12.50 Gross Pay: $500.00 Deductions: Federal withholding (20.00%): $19.50 state withholding (9.00%): $8.78 Total Deduction: $28.28 Federal withholding (15.00%): $75.00 state withholding (8.00%); $48.00 Total Deduction: $115.00 Net Pay: $69.23 Net Pay: $385.00

fullscreen
check_circle

Expert Answer

Step 1

The program has the following algorithm:

 

  • In the main method do the following operations,
  • Get the employee name, number of hours worked in a week, hourly pay rate, federal tax withholding rate and state tax withholding rate from the user.
  • Calculate gross pay by call the method.
    • Multiply hourly pay rate and hours worked in a week for calculating the gross pay.
  • Calculate federal withholding by call the method
    • Multiply gross pay and federal tax withholding rate for calculating the federal withholding.
  • Calculate state withholding by call the method
    • Multiply gross pay and state tax withholding rate for calculating the state withholding.
  • Calculate total deduction by call the method
    • Adding federal withholding and state withholding for calculating total deduction.
  • Calculate net pay by call the method
    • Subtracting gross pay and total deduction for calculating net pay.
Step 2

Program:

 

//main method

 

//Import required packages

import java.util.*;

 

//Definition of class EmpPayroll

public class EmpPayroll

{

    //Definition of main class

    public static void main(String args[])

    {

    //Create an object for scanner class

        Scanner inputnew Scanner(System.in);

        Pay value = new Pay();

 

        //Get the employee name

        System.out.print("Enter employee's name: ");

        value.setName(input.next());

 

        //Get the number of hours worked

        System.out.print("Enter number of hours worked in a week: ");

        value.setHours(input.nextDouble());

 

        //Get the hourly pay rate

        System.out.print("Enter hourly pay rate: ");

        value.setPayrate(input.nextDouble());

       

        //Get the federal tax

        System.out.print("Enter federal tax withholding rate:");

        double fed=input.nextDouble();

      

        //Get the state tax

         System.out.print("Enter state withholding rate:");

        double withHold=input.nextDouble();

 

        //Get the values

        double grossAmount = value.grossPay(value.getPayrate(), value.getHours());

 

        System.out.println();

       

        //Print the values prompted from the user

        System.out.printf("Employee Name: %s\n",value.getName());

        System.out.printf("Hours Worked:%.2f\n", value.getHours());

        System.out.printf("Pay Rate:$%.2f\n",value.getPayrate());

        System.out.printf("Gross Pay:$%.2f\n", grossAmount);

        System.out.println("Deductions");

        System.out.print("\tFederal Withholding (20.00%):$");

        System.out.printf("%.2f", value.fedTax(fed,grossAmount));

        System.out.print("\n\tState Withholding (9.00%):$");

        System.out.printf("%.2f",value.stTax(withHold,grossAmount));

        System.out.print("\n\tTotal Deduction:$");

        System.out.printf("%.2f",(value.fedTax(fed,grossAmount) + value.stTax(withHold,grossAmount)));

        System.out.print("\nNet Pay:$");

        System.out.printf("%.2f",(grossAmount - (value.fedTax(fed,grossAmount) + value.stTax(withHold,grossAmount))));

       

    }

 

}

 

//Pay.java

 

//Definition of class Pay

public class Pay

{

    //Declare the required variable

    private String name;

    private double hrsWorked;

    private double hourPay;

   

    //Invoke the constructor

    public Pay()

    {

 

    }

 

    //Invoke the parameterized constructor

    public Pay(String n, double hw, double hpr)

    {

    //Assign the values

        this.name = n;

        this.hrsWorked = hw;

        this.hourPay = hpr;

    }

 

    //Definition of method grossPay()

    public double grossPay(double hRate, double hWork)

    {

    //Calculate gross pay

        double gPay = (hRate * hWork);

       

        //Return gross pay

        return gPay;

    }

 

  //Definition of method fedTax()

    public double fedTax(double fed, double gross)

    {

    //Return federal tax

        return fed * gross;

    }

 

    //Definition of method stTax()

    public double stTax(double withHold,double gross)

    {

    //Return state tax

        return withHold * gross;

    }

 

    //Definition of getName() method

    public String getName() {

        return name;

    }

 

 

    //Definition of setName method

    public void setName(String name) {

        this.name = name;

    }

 

 

    //Definition of gethours() method

    public double getHours() {

        return hrsWorked;

    }

 

  //Definition of setHours() method

    public void setHours(double hoursWorked) {

        this.hrsWorked = hoursWorked;

    }

 

//Definition of getPayrate()

    public double getPayrate() {

        return hourPay;

    }

 

//Definition of setPayrte()

    public void setPayrate(double hourlyPayRate) {

        this.hourPay = hourlyPayRate;

    }

 

}

 

 

 

Step 3

Output1:

 

...
fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Engineering

Programing

Related Computer Engineering Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Write a program in Eclipse that contains 2 methods, main and printLine.

A: Program plan: Import necessary packages.Define a class named “PrintCheck”.Define a method called “pr...

question_answer

Q: Analyze the following code: Code 1: int number = 45;boolean even; if (number % 2 == 0) even = true;e...

A: Hey, since there are multiple questions posted, we will answer first question. If you want any speci...

question_answer

Q: Based on a decision tree structure - what are three decisions that may be applicable to a project? w...

A: A decision tree is a supervised learning technique which acts as a decision support tool. It forms a...

question_answer

Q: For this program you need to use Eclipse

A: The program has the following algorithm:Declare the necessary variables within the “main()” function...

question_answer

Q: What values will print? Use Eclipse to verify it • Only write the answerdouble x = Math.sqrt(4);Syst...

A: Solutions://Define the classpublic class Example{     //Define the main() method     public static v...

question_answer

Q: Assume that a firm has already implemented a KMS system, as a manager, how do you ensure that learni...

A: The given case study describes the internal knowledge assets of the organization and details about t...

question_answer

Q: What is DPI

A:  DPI means Dots Per Inch which measures the number of dots placed within squared region of 1-inch di...

question_answer

Q: Write a program called StudentTable that prints the below table. Use only print() orprintf(). DO NOT...

A: The "print()" and "printf()" function are available in C language and "println()" function is only a...

question_answer

Q: What is the equivalent 2's complement representation for -15 in 16-bit hexadecimal representation? a...

A: For representing –15 in 2’s complement notation following steps should be followed:Find the binary e...