In: Computer Science
Write the program in Java.
Create project PaystubTest2 that is a Paystub calculator with program Paystub##.java (where ## is your initials) based on user input. (10 points)
You must use the ReadStringFromUser and ReadFloatFromUser methods in the program to obtain user input. (20 points)
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. (50 points)
INPUT
The application must be able to collect the following “required” information for each employee:
OUTPUT
These are the outputs:
PROCESS
For each employee (HINT: Do while QUIT is not entered - if( strResponse.toUpperCase().equals("QUIT") )) 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
You must create a JavaDoc for this project. (10 points)
Be sure to include a print screen of your test results. (10 points)
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 john Lee
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
-----------------------------------------------------
-----------------------------------------------------
PROGRAM:
Please find below the javaDoc style commented program:
package test;
/**
* The program implements the method to calculate the
* pay stub for employee by asking the user
* to enter employee details
* Paystub will show calculation for individual
* as well as totals of pays at the end
* when user quits the program *
*
* @author Student Name
* @version 1.0
* @since 2020-7-11
*/
import java.util.Scanner;
import java.text.DecimalFormat;
public class PaystubAA {
static Scanner scObj = new Scanner(System.in);
static DecimalFormat format = new DecimalFormat("#.##");
public static void main(String[] args) {
String Name;
float hourlyWage;
int hoursWorked, withHoldings;
char maritalStatus;
double grossPay,socialSecurityTax,medicareTax, FICATax, netIncome, federalTax;
double totalEmployee = 0, totalGross = 0, totalScoailSecurityTax = 0, totalMedicareTax = 0, TotalFICATax = 0,totalNetIncome=0, totalFederalTax = 0;
System.out.print("Enter Employee Name (type 'Quit' to end program): ");
Name= ReadStringFromUser();
while(!Name.toUpperCase().equals("QUIT")) {
System.out.print("Hourly Wage: ");
hourlyWage = ReadFloatFromUser();
System.out.print("Hours worked: ");
hoursWorked = scObj.nextInt();
System.out.print("Withholding Exemptions(between 0 to 10): ");
withHoldings= scObj.nextInt();
while(withHoldings<0 || withHoldings>10)
{
System.out.print("Withholding exemption to be between 1 to 10. Enter again:");
withHoldings= scObj.nextInt();
}
scObj.nextLine();
System.out.print("Marital Status(S= Single, M=Married): ");
maritalStatus = scObj.next().charAt(0);
grossPay=calcGrossPay(hourlyWage, hoursWorked);
medicareTax=grossPay* (.0145);
socialSecurityTax = grossPay*(.062);
FICATax = medicareTax+socialSecurityTax;
federalTax= FederalTax(grossPay, maritalStatus, withHoldings);
netIncome=grossPay-FICATax-federalTax;
System.out.println("Paycheck for "+Name);
System.out.println("Gross Income:\t\t\t\t $"+format.format(grossPay)+
"\nless Medicare Tax:\t\t\t $"+format.format(medicareTax)+
"\nless Social Security Tax:\t\t $"+format.format(socialSecurityTax)+
"\nless FICA Tax:\t\t\t\t: $" + format.format(FICATax)+
"\nless Federal Income Tax Withheld:\t$"+format.format(federalTax)+
"\nNet Income:\t\t\t\t$"+format.format(netIncome));
totalEmployee++;
totalFederalTax= totalFederalTax+federalTax;
totalMedicareTax=totalMedicareTax+medicareTax;
totalScoailSecurityTax=totalScoailSecurityTax+socialSecurityTax;
totalGross= totalGross+grossPay;
totalNetIncome= totalNetIncome+netIncome;
TotalFICATax=TotalFICATax+FICATax;
scObj.nextLine();
System.out.println("\n-----------------------------------------------\n");
System.out.print("Enter next employee Name (type 'Quit' to end program): ");
Name= ReadStringFromUser();
}
System.out.println("Grand PayCheck Totals: ");
System.out.println("\n***********************\n");
System.out.println("Total Gross Income:\t\t\t $"+format.format(totalGross)+
"\nTotal Medicare Tax:\t\t\t $"+format.format(totalMedicareTax)+
"\nTotal Social Security Tax:\t\t $"+format.format(totalScoailSecurityTax)+
"\nTotal FICA Tax:\t\t\t\t $" + format.format(TotalFICATax)+
"\nTotal Federal Income Tax Withheld:\t $"+format.format(totalFederalTax)+
"\nTotal Net Income:\t\t\t$"+format.format(totalNetIncome));
}
/**
* This method is used to calculate the federal tax. .
* @param grossPay: This is grossPay passed to this method
* @param maritalStatus: This is maritalStatus passed to this method from calling method
* @param withholdings: This is withholdings numbers passed to this method
* @return double This returns calculated ferderal tax based on the params passed in it.
*/
private static double FederalTax(double grossPay, char maritalStatus, int withHoldings) {
grossPay=grossPay- (withHoldings * 55.77);
double tax=0;
if(maritalStatus == 'S') {
if(grossPay>=51 && grossPay<500.99)
tax=(grossPay-51)*.10;
else if(grossPay>=501 && grossPay<2500.99) {
tax=45+ (grossPay-500)*.15;System.out.println("tax is: "+tax);}
else if(grossPay>=2501 && grossPay<=5000)
tax=345+ (grossPay-2500)*.20;
else
tax=845+ (grossPay-5000)* .25;
}
else {
if(grossPay>=51 && grossPay<500.99)
tax=(grossPay-51)*.05;
else if(grossPay>=501 && grossPay<2500.99)
tax=45+ (grossPay-500)*.10;
else if(grossPay>=2501 && grossPay<=5000)
tax=345+ (grossPay-2500)*.15;
else
tax=845+ (grossPay-5000)* .20;
}
return tax;
}
/**
* This method is used to calculate the gross pay.
* if hours are less than or equal to 40, pay is hour multiplied by hourly wags
* if hours are more than 40, employee gets one and half time pay for hours
* more than 40
* @param hourlyRate: value of hoursly rate
* @param hoursWorked: total hours worked
* @return double calculation of gross pay based on the total hours
*/
private static double calcGrossPay(float hourlyWage, int hoursWorked) {
if(hoursWorked <=40)
return hourlyWage*hoursWorked;
else
return ((hourlyWage*40)+ ((hourlyWage*1.5)*(hoursWorked-40)));
}
/**
* This method is used to read the float numbers from user .
* @param none: nothing will be passed to this method
* @return float This returns entered float value by user at runtime
*/
private static float ReadFloatFromUser() {
float inputFloat = scObj.nextFloat();
return inputFloat;
}
/**
* This method is used to read the String inputs from user .
* @param none: nothing will be passed to this method
* @return float This returns entered string by user at runtime
*/
private static String ReadStringFromUser() {
String enteredString = scObj.nextLine();
return enteredString;
}
}
SCREENSHOT:
OUTPUT:
**Please note that calculations are as per given guideline and the output sample in question have some errors in calculations. The program output will calculate the correct values. Thanks!!!