menu
bartleby
search
close search
Hit Return to see all results

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

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_circleAnswer
Step 1

Program plan:

Class name: EmpPayroll

  • Import the required header files.
  • Define the class "EmpPayroll"
  • Define the main class
    • Create an object for scanner class.
    • Get the employee name, number of hours worked, hourly pay rate, federal tax and state tax from the user
    • Compute the values and print the result

Class name: Pay.java

  • Define the class "Pay"
  • Invoke the parameterized and non-paramaterized constructor.
  • Define the method grossPay(), fedTax(), stTax().
  • Define the mutator and accessor method

 

 

Step 2

Program:

EmpPayroll.java

//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))));

       

    }

 

}

Step 3

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

...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Our solutions are written by experts, many with advanced degrees, and available 24/7

See Solution
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: Construct the XOR operator using only AND, OR, and NOT gates.

A: XOR gate:An XOR gate is referred to an Exclusive OR gate. The output of an XOR gate is “1” only when...

question_answer

Q: How to write a function in python that takes a string s = kkeeepinng and returns the non-repeating c...

A: Program plan:Inside the function, create two empty list named “dup_list[]” and “non_dup_list[]”.Use ...

question_answer

Q: How do I get this flat list table into 1NF, 2NF and 3NF?

A: Normalization:Normalization is a process of dividing the tables by more than one idea into set of ta...

question_answer

Q: 1.6 Compute the scalar cardinality and the fuzzy cardinality for each of thefollowing fuzzy set.

A: The scalar cardinality of a fuzzy set is calculated using the formula:

question_answer

Q: Which filenames would be a subsequent ls command display?$ lsabc abd abe abf abg abh$ rm abc ab*rm: ...

A: To describe which filenames the subsequent ls command display.

question_answer

Q: Assume the following declarations and initializations (MIN, MAX, num) are made just before each sub-...

A: Since these are separate blocks of code, for the purpose of demonstration we put the blocks in same ...

question_answer

Q: Note: Numbers greater then 3,999 require symbols with lines over letters. We can't use these, so use...

A: Note: The given python program has been compiled and executed in "repl.it" online complier.Screensho...

question_answer

Q: (a) Find an nfa with three states that accepts the language L = {an : n ≥ 1} ∪ {bmak : m ≥ 0, k ≥ 0}

A: Graphical representation of NFA:The starting state is denoted by an empty incoming arc, the vertices...

question_answer

Q: I have a HW that is asking me to draw on ERD diagram for a simple purchasing system that has order w...

A: ERD diagram for Purchasing System:The ERD diagram for the simple purchasing system is as follows:

Sorry about that. What wasn’t helpful?