Write a java program to calculate a payroll payment check for the following spec
ID: 3802830 • Letter: W
Question
Write a java program to calculate a payroll payment check for the following specs:
2. The java program class name: Q3
3. The program should allocate constants with final data type for tax rates to include:
(1) local rate: 5%
(2) state rate: 2.5%
(3) federal rate: 10%
(4) medical insurance: 2%
(5) unemployment insurance: 2.5%
(6) social security contribution: 5%
4. The program accepts these data from keyboard:
(1) employee first and last name in string format
(2) social security number in string type variable format as: xxx-xx-xxxx
(3) salary period in string format: Month & Year (i.e February,2017)
(3) monthly income in integer
5. Calculate total tax amount, minus from annual income for net salary payment
and O/P the calculated results in this format with one console O/P statement:
Monthly Payroll Salary Payment Check
==========================================
Employee Name: xxxxxxxx xxxxxxxxx
SSN: xxx-xx-xxxx
salary period: Month & Year (i.e February,2017)
gross payment: xxxxx
deductions:
(1) local tax: xxx.xx
(2) state tax: xxx.xx
(3) federal tax: xxx.xx
(4) medical insurance: xxx.xx
(5) unemployment insurance: xxx.xx
(6) social security contribution: xxx.xx
Total deduction: xxxx.xx
Net payment: xxxx.xx
End of Job
Explanation / Answer
Please find below the Q3.java class :::::
import java.util.Scanner;
public class Q3
{
public static void main(String args[])
{
// declaring tax rates as constants using final data type
final double local_rate = 0.05;
final double state_rate = 0.25;
final double federal_rate = 0.1;
final double medical_insurance = 0.02;
final double unemployment_insurance = 0.25;
final double social_security_contribution = 0.05;
Scanner sc = new Scanner(System.in);
//Takes employee's first name
System.out.println("Enter the Employee's first name:");
String first_name = sc.next();
//Takes employee's last name
System.out.println("Enter the Employee's last name:");
String last_name = sc.next();
//Takes social security number in the given format
System.out.println("Enter the Employee's social security number in the format xxx-xx-xxxx:");
String ssn = sc.next();
//checks if the social security number entered by the user is as per the format
if(!((ssn.charAt(3) == '-') && (ssn.charAt(6) == '-')))
System.out.println("Social security number entered in wrong format.");
//Takes salary period month and year in the given format
System.out.println("Enter the salary period in the format, Month,Year:");
String salary_period = sc.next();
//Takes monthly income of the employee
System.out.println("Enter the monthly income of the employee:");
double income = sc.nextInt();
// Gross amount is the salary per year which is calculated by multiplying salary per month and 12(i.e no of months in a year)
double gross_amount = income * 12;
// Prints the above entered employee's details
System.out.println("Monthly Payroll Salary Payment Check");
System.out.println("==========================================");
System.out.println("Employee Name: " + first_name +" " + last_name);
System.out.println("SSN: " + ssn);
System.out.println("salary period: " + salary_period);
System.out.println("gross payment: " + gross_amount);
//Calculates the tax amount payable upon the gross amount
double lt = local_rate * gross_amount;
double st = state_rate * gross_amount;
double fr = federal_rate * gross_amount;
double mi = medical_insurance * gross_amount;
double ui = unemployment_insurance * gross_amount;
double ssc = social_security_contribution * gross_amount;
System.out.println("");
System.out.println("");
// Prints the above calculated various tax amounts which are payable
System.out.println("Deductions: ");
System.out.println("(1) local tax: " + lt);
System.out.println("(2) state tax: " + st);
System.out.println("(3) federal tax: " + fr);
System.out.println("(4) medical insurance: " + mi);
System.out.println("(5) unemployment insurance: " + ui);
System.out.println("(6) social security contribution: " + ssc);
double total_deduction = lt+st+fr+mi+ui+ssc; // calculates total_deduction by adding up all the tax amounts
double net_payment = gross_amount - total_deduction; // calculates net_payment by subtracting total_deduction from gross salary
System.out.println("");
System.out.println("");
// Prints total_deduction and net_payment as caculated above
System.out.println("Total deduction: " + total_deduction );
System.out.println("Net payment: "+ net_payment);
// Ends the program
System.out.println("End of Job");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.