Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Understanding Sequential Statements Summary In this lab, you complete a Java program with the provided data files. The program calculates the amount of tax withheld

Understanding Sequential Statements

Summary

In this lab, you complete a Java program with the provided data files. The program calculates the amount of tax withheld from an employees weekly salary, the tax deduction to which the employee is entitled for each dependent, and the employees take-home pay. The program output includes state tax withheld, federal tax withheld, dependent tax deductions, salary, and take-home pay.

Instructions

  1. Ensure the file named Payroll.java is open.

  2. Variables have been declared and initialized for you as needed, the output statements have been written and the input object has been declared and initialized for you. Read the code carefully before you proceed to the next step.

  3. Write the Java code needed to perform the following:

    • Calculate state withholding tax (stateTax) at 6.5 percent
    • Calculate federal withholding tax (federalTax) at 28.0 percent.
    • Calculate dependent deductions (dependentDeduction) at 2.5 percent of the employees salary for each dependent.
      • Calculate total withholding (totalWithholding) as stateTax + federalTax + dependentDeduction.
      • Calculate take-home pay (takeHomePay) as salary minus total withholding.
    • Compile and execute your program by clicking the Run button. You should get the following output:
      State Tax: $81.25 Federal Tax: $350.00000000000006 Dependents: $62.5 Salary: $1250 Take-Home Pay: $756.25
    • In this program, the variables salary and numDependents are initialized with the values 1250.00 and 2. To make this program more flexible, modify it to accept interactive input for salary and numDependents. when running the code Output must read Dependents, state tax, federal tax, salary, take home pay

image text in transcribedimage text in transcribedimage text in transcribed

import java.util.Scanner; public class Payroll { static float stateTax 6.5f; static float federallax 28.of; static float dependentDeduction 2.5f; public float calculatestateTax(float salary) { return (salary*Payroll.stateTax / 100); } public float calculateFederalTax(float salary) { return (salary*Payroll. federalTax / 100); } public float calculateDependentDeductions (float salary, int num) { float total = (salary*Payroll.dependentDeduction / 100); total *= num; return total; } public static void main(String[] args) { Payroll obj = new Payroll(); Payroll obj = new Payroll(); Scanner in = new Scanner(System.in); while(true) { System.out.println("Enter Salary and number of dependents (press q to quit)"); String val = in.next(); if(val.equals("q")) { break; } else { float salary; salary = Float.parseFloat(val); int numDependents = in.nextInt(); float stateTax = obj.calculatestateTax(salary); float federalTax = obj.calculateFederalTax(salary); float dependent = obj.calculatedependentDeductions (salary, numDependents); float totalwithholding = stateTax + federalTax + dependent; float takeHome = (salary - totalwithholding); System.out.println("State Tax: $"+ stateTax); break; } else { float salary; salary = Float.parseFloat(val); int numDependents = in.nextInt(); float stateTax = obj.calculatestateTax(salary); float federalTax = obj.calculateFederalTax(salary); float dependent = obj.calculateDependentDeductions (salary, numDependents); float totalwithholding stateTax + federalTax + dependent; float takeHome = (salary - totalwithholding); System.out.println("state Tax: $"+ stateTax); System.out.println("Federal Tax: $"+ federalTax); System.out.println("Dependents: $"+ dependent); System.out.println("Salary: $"+ salary); System.out.println("Take-Home Pay: $"+ takeHome); } } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

What are topics included within employee services?

Answered: 1 week ago