In: Computer Science
For this assignment, you will take on the role of software developer as part of a team of developers for a retail company. The payroll manager of the company has tasked you with developing a Java program (if you can put it in NetBeans that would be awesome) to quickly calculate an employee’s weekly gross and net pay. The program must prompt the user to enter the employee’s name, rate of pay, and hours worked. The output will display the information entered into the program along with the calculations for gross pay, total amount of deductions, and net pay.
In this coding assignment, you will utilize the Java syntax and techniques you learned while reviewing the required resources for Week 1. You may select appropriate variable names as long as proper Java syntax is used. You will also submit your source code.
Input:
In the input section, utilize Java syntax and techniques to input
the employee’s name, rate of pay, and hours worked. The input
should be completed either via keyboard or via file.
Processing:
In the processing section, the following calculations will need to
be performed in the processing section:
The following calculations are used to calculate each deduction:
Total deductions = Federal Tax amount + State Tax amount + Medicare amount + Social Security amount + Unemployment Insurance amount
Output:
The Java program should display the following information:
Hi,
Please find below code as per your requirement.
Let me know if you have any doubt/concerns in this via comments.
Hope this answer helps you.
Thanks.
/**********************JAVA CODE*********************/
/***************EmployeePay.java***************/
import java.text.DecimalFormat;
import java.util.Scanner;
public class EmployeePay {
public static void main(String[] args) {
//Scanner class is used to get user input using console i.e. System.in
Scanner sc = new Scanner(System.in);
//Decimal Format is used to format all amount upto 2 decimal places
DecimalFormat df = new DecimalFormat("#.##");
System.out.print("Please enter Employee Name: ");
//reading user input for employee name into employeeName variable
String employeeName = sc.nextLine();
System.out.print("Please enter Rate of Pay: ");
//reading user input for Rate of Pay into rateOfPay variable
double rateOfPay = Double.parseDouble(sc.nextLine());
System.out.print("Please enter Total Hours worked: ");
//reading user input for Total Hours worked into totalHoursWorked variable
int totalHoursWorked = Integer.parseInt(sc.nextLine());
//initializing variables for gross pay and overtime
double grossPay = 0;
int overtime = 0;
//if total hours worked is greater that 40 hours
if(totalHoursWorked > 40) {
overtime = totalHoursWorked - 40;
grossPay = ((totalHoursWorked - 40) * (rateOfPay * 1.5)) + (40 * rateOfPay);
} else { //if total hours less than equal to 40 hours
grossPay = totalHoursWorked * rateOfPay;
}
//initializing variables and calculating all deductions
double deductions = 0;
double federalTax = ((grossPay * 15)/100);
double stateTax = ((grossPay * 3.07)/100);
double medicare = ((grossPay * 1.45)/100);
double socialSecurity = ((grossPay * 6.2)/100);
double unemploymentInsurance = ((grossPay * 0.07)/100);
//summing up all the deductions
deductions = federalTax + stateTax + medicare + socialSecurity + unemploymentInsurance;
//calculating net pay
double netPay = grossPay - deductions;
//Printing all details of Pay also used DecimalFormatter to format amount
System.out.println("Employee Name: "+employeeName);
System.out.println("Rate of Pay: $"+rateOfPay);
System.out.println("Hours worked: "+totalHoursWorked);
System.out.println("Overtime worked: "+overtime);
System.out.println("Gross Pay: $"+df.format(grossPay));
System.out.println("Total Amount deductions: $"+df.format(deductions));
System.out.println("Net Pay: $"+df.format(netPay));
}
}
/*****************Code output sample screenshot***************/