Question

In: Computer Science

This program is written in Java and should be modularized in methods in one class. This...

This program is written in Java and should be modularized in methods in one class.

This program will calculate the Gross Earnings, FICA tax (Medicare and Social Security taxes), Federal Tax Withheld, and Net Amount of the payroll check for each employee of a company. The output must contain numbers with 2 decimal places. The user input must be validated – if incorrect data is entered, send an error message to the user.

INPUT

The application must be able to collect the following “required” information for each employee:

  1. Name
  2. Hourly Wage (must be a positive number)
  3. Hours Worked (must be a positive number)
  4. Withholding Exemptions (valid values are from 0 to 10)
  5. Marital Status (Single or Married)

OUTPUT

These are the outputs:

  1. For each employee display the following:
    1. Gross Earnings
    2. FICA Tax (display both Medicare and Social Security taxes)
    3. Federal Income Tax Withheld
    4. Net Earnings

PROCESS

For each employee (HINT: Do while QUIT is not entered) calculate the following for their individual payroll for the week. Use an array to hold the gross pay amounts and print the grand payroll total once the user types QUIT.

Gross earnings: Hourly wage times hours worked (with time and a half after 40 hours).

FICA Tax: sum of 6.2% of the total wages (Social Security tax) and 1.45% of total wages (Medicare tax)

Federal Income Tax Withheld: Subtract $55.77 from the gross earnings for each withholding exemption giving the Adjusted Gross Income. Based on the Adjusted Gross Income, use the following parameters to determine the federal tax based on marital status:

Adjusted Gross Income

Income Tax Withheld (S)

Income Tax Withheld (M)

$0 to $50.99

$0

$0

$51 to $500.99

10% over $51

5% over $51

$501 to $2,500.99

$45.00 + 15% of amount over $500.00

$22.50 + 10% of amount over $500.00

$2,501 to $5,000

$345.00 + 20% of amount over $2,500

$225.50 + 15% of amount over $2,500

Over $5,000

$845.00 + 25% of amount over $5,000

$600.50 + 20% of amount over $5,000

Net Earnings: Gross Earnings – FICA taxes – Federal Income Tax Withheld

Here is an example of the output format:

Paystub Calculator

-------------------------------------------------------

Employee Name:(type 'Quit' to end program)

Sam Smith

Hourly Wage: 10

Hours Worked: 40

Withholding Exemptions: 0

Marital Status (S = Single, M = Married): M

Paycheck for Tomie Gartland

Gross Income:                           $      400.00

less Medicare Tax:                     $        5.80

less Social Security Tax:              $       24.80

less FICA Tax:                         $       30.60

less Federal Income Tax Withheld:      $       17.45

Net Income:                             $      351.95

-----------------------------------------------------

Employee Name:(type 'Quit' to end program)

Sally Smith

Hourly Wage: 25

Hours Worked: 50

Withholding Exemptions: 2

Marital Status (S = Single, M = Married): M

Paycheck for Sally Smith

Gross Income:                           $     1375.00

less Medicare Tax:                     $       19.94

less Social Security Tax:              $       85.25

less FICA Tax:                         $      105.19

less Federal Income Tax Withheld:      $       98.85

Net Income:                             $     1170.97

-----------------------------------------------------

Employee Name:(type 'Quit' to end program)

Quit

Grand Paycheck Totals--------------------------------

-----------------------------------------------------

Total Gross Income:                     $     1775.00

Total Medicare Tax:                     $       25.74

Total Social Security Tax:              $      110.05

Total FICA Tax:                         $      135.79

Total Income Tax Withheld:              $      116.30

Total Net Income:                       $     1522.92

-----------------------------------------------------

-----------------------------------------------------

Solutions

Expert Solution

Explanation:

I have implemented all the methods in a single class as mentioned in the question. I have used various methods to calculate the gross earnings,tax,income, marital status,etc.I have used total variables to store the totals of all incomes,taxes,etc.I have also shown the output of the code,please find it attached with the answer.I have used DecimalFormat to format the output upto two decimal places.Please upvote if you liked my answer and comment of you need any modification or explanation

//code starts

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.util.Scanner;

public class GrossEarnings {

   public double getGrossIncome(float hourlyWage, float hoursWorked) {
       double grossIncome = 0;
       if (hoursWorked > 40) {
           grossIncome += (hourlyWage * 1.5 * (hoursWorked - 40));
           hoursWorked = 40;
       }
       grossIncome += hourlyWage * hoursWorked;
       return grossIncome;

   }

   public double getSocialSecurityTax(double grossIncome) {
       double socialSecurityTax = 0;
       socialSecurityTax = (6.2 * grossIncome) / 100;
       return socialSecurityTax;

   }

   public double getMedicareTax(double grossIncome) {
       double medicalTax = 0;
       medicalTax = (1.45 * grossIncome) / 100;
       return medicalTax;

   }

   public double getFederalTax(double grossIncome, int withHolding, char maritalStatus) {
       double federalTax = 0;
       double adjustGrossEarning = grossIncome - withHolding * 55.77;
       switch (maritalStatus) {
       case 'M':
           if (adjustGrossEarning >= 0 && adjustGrossEarning <= 50.99)
               return 0;
           else if (adjustGrossEarning >= 51 && adjustGrossEarning <= 500.99) {
               federalTax += (5 * (adjustGrossEarning - 51)) / 100;
               return federalTax;
           } else if (adjustGrossEarning >= 501 && adjustGrossEarning <= 2500.99) {
               federalTax += 22.50 + (10 * (adjustGrossEarning - 500)) / 100;
               return federalTax;
           } else if (adjustGrossEarning >= 2501 && adjustGrossEarning <= 5000) {
               federalTax += 225.50 + (15 * (adjustGrossEarning - 2500)) / 100;
               return federalTax;
           } else if (adjustGrossEarning > 5000) {
               federalTax += 600.50 + (20 * (adjustGrossEarning - 5000)) / 100;
               return federalTax;
           }
           break;
       case 'S':
           if (adjustGrossEarning >= 0 && adjustGrossEarning <= 50.99)
               return 0;
           else if (adjustGrossEarning >= 51 && adjustGrossEarning <= 500.99) {
               federalTax += (10 * (adjustGrossEarning - 51)) / 100;
               return federalTax;
           } else if (adjustGrossEarning >= 501 && adjustGrossEarning <= 2500.99) {
               federalTax += 45.00 + (15 * (adjustGrossEarning - 500)) / 100;
               return federalTax;
           } else if (adjustGrossEarning >= 2501 && adjustGrossEarning <= 5000) {
               federalTax += 345.00 + (20 * (adjustGrossEarning - 2500)) / 100;
               return federalTax;
           } else if (adjustGrossEarning > 5000) {
               federalTax += 845.00 + (25 * (adjustGrossEarning - 5000)) / 100;
               return federalTax;
           }

       default:
           break;
       }
       return federalTax;

   }

   public static void main(String[] args) throws IOException {
       GrossEarnings grossEarnings = new GrossEarnings();
       DecimalFormat df = new DecimalFormat("##.00");
       double totalGrossIncome = 0;
       double totalMedicalTax = 0;
       double totalSocialSecurityTax = 0;
       double totalIncomeTax = 0;
       double totalNetIncome = 0;
       Scanner scanner = new Scanner(System.in);
       BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
       System.out.println("Paystub Calculator");
       System.out.println("----------------------------------------");
       while (true) {
           System.out.println("Employee Name:(type 'Quit' to end program)");
           String name = bufferedReader.readLine();// scanner.next();
           if (name.trim().compareTo("Quit") == 0)
               break;
           System.out.print("Hourly Wage:");
           float hourlyWage = Float.parseFloat(bufferedReader.readLine());
           System.out.print("Hours Worked:");
           float hoursWorked = Float.parseFloat(bufferedReader.readLine());
           System.out.print("Withholding Exemptions:");
           int withholdingExemptions = Integer.parseInt(bufferedReader.readLine());
           System.out.print("Marital Status (S = Single, M = Married):");
           char maritalStatus = bufferedReader.readLine().charAt(0);
           double grossIncome = grossEarnings.getGrossIncome(hourlyWage, hoursWorked);
           System.out.println("Gross Income:\t\t\t $" + df.format(grossIncome));
           double medicalTax = grossEarnings.getMedicareTax(grossIncome);
           System.out.println("less Medicare Tax:\t\t $" + df.format(medicalTax));
           double securityTax = grossEarnings.getSocialSecurityTax(grossIncome);
           System.out.println("less Social Security Tax:\t $" + df.format(securityTax));
           System.out.println("less FICA Tax:\t\t\t $" + df.format((medicalTax + securityTax)));
           double federalTax = grossEarnings.getFederalTax(grossIncome, withholdingExemptions, maritalStatus);
           System.out.println("less Federal Income Tax Withheld: $" + df.format(federalTax));
           System.out
                   .println("Net Income:\t\t\t $" + df.format((grossIncome - medicalTax - securityTax - federalTax)));
           totalGrossIncome += grossIncome;
           totalIncomeTax += federalTax;
           totalMedicalTax += medicalTax;
           totalSocialSecurityTax += securityTax;
           totalNetIncome += grossIncome - medicalTax - securityTax - federalTax;

       }
       scanner.close();
       System.out.println("Grand Paycheck Totals--------------------------------");
       System.out.println("Total Gross Income: \t\t $" + df.format(totalGrossIncome));
       System.out.println("Total Medicare Tax: \t\t $" + df.format(totalMedicalTax));
       System.out.println("Total Social Security Tax: \t $" + df.format(totalSocialSecurityTax));
       System.out.println("Total FICA Tax: \t\t $" + df.format((totalMedicalTax + totalSocialSecurityTax)));
       System.out.println("Total Income Tax Withheld: \t $" + df.format(totalIncomeTax));
       System.out.println("Total Net Income: \t\t $" + df.format(totalNetIncome));

   }

}

Output:


Related Solutions

Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
Program should be written in Java b) The computer program should prompt the user (You are...
Program should be written in Java b) The computer program should prompt the user (You are the user) to enter the answers to the following questions: What is your city of birth? What is your favorite sport? If you could live anywhere in the world, where would you like to live? What is your dream vacation? Take this information and create a short paragraph about the user and output this paragraph. You may use the Scanner class and the System.out...
rite a java program that uses the methods written in this section to do the following:Prompt...
rite a java program that uses the methods written in this section to do the following:Prompt the user for a number of grades using the getValidInput method. Ensure the number of grades is greater than 1 and less than 30. The error message is “You must enter a number between 1 and 30, please re-enter:”Prompt the user to enter the requested grades and total marks using the calculateLetterGrade method. The grades should be between 0 and 100. Display an appropriate...
JAVA PROGRAM: Creates a Bank Account class with one checking account and methods to withdraw and...
JAVA PROGRAM: Creates a Bank Account class with one checking account and methods to withdraw and deposit. Test the methods in the main function.
This program should be written in Java language. Given the uncertainty surrounding the outbreak of the...
This program should be written in Java language. Given the uncertainty surrounding the outbreak of the Coronavirus disease (COVID-19) pandemic, our federal government has to work tirelessly to ensure the distribution of needed resources such as medical essentials, water, food supply among the states, townships, and counties in the time of crisis. You are a software engineer from the Right Resource, a company that delivers logistic solutions to local and state entities (schools, institutions, government offices, etc). You are working...
The following program will be written in JAVA. Create a class called complex performing arithmetic with...
The following program will be written in JAVA. Create a class called complex performing arithmetic with complex numbers. Write a program to test your class.                         Complex numbers have the form:                         realPart + imaginaryPart * i                                               ___                         Where i is sqrt(-1)                                                 Use double variables to represent data of the class. Provide a constructor that enables an object of this class to be initialized when it is declared. The constructor should contain default values in...
A java program with classes and methods to manage employment. Program should be able to store/add...
A java program with classes and methods to manage employment. Program should be able to store/add employees, calculate payroll, display or schedule shifts. All classes should have at least a null constructor and copy constructor. Other constructors are up to your discretion. Include all necessary accessors and modifiers. To test the classes, create a container class with simply a main() method. The container class will have attributes that are class objects of each of the classes you create. The main()...
write program that develop a Java class Dictionary to support the following public methods of an...
write program that develop a Java class Dictionary to support the following public methods of an abstract data type: public class Dictionary { // insert a (key, value) pair into the Dictionary, key value must be unique, the value is associated with the key; only the last value inserted for a key will be kept public void insert(String key, String value); // return the value associated with the key value public String lookup(String key); // delete the (key, value) pair...
How to write a Java program that has a base class with methods and attributes, subclasses...
How to write a Java program that has a base class with methods and attributes, subclasses with methods and attributes. Please use any example you'd like.
There is a Java program that is missing one recursive function: public class Ackermann { /*...
There is a Java program that is missing one recursive function: public class Ackermann { /* / n+1 when m = 0 * ack(m,n) = | ack(m-1,1) when m > 0 and n = 0 * \ ack(m-1, ack(m, n-1)) otherwise */ public static int ack(int m, int n) { return 0; } /* Ackermann's Function Test Framework * * Be extremely careful with these test cases. Ackermann's grows very fast. * For example, ack(4, 0) = 13, but ack(5,0)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT