In: Computer Science
6) Create the following in a Java Program:
Create payroll system
Prompt the user to enter payroll information
Employee name and create variable for scanner
Hours worked
Hourly pay rate
Federal tax rate
State tax rate
Declare variable doubles for gross pay, federal, state and total
deduction
Display payroll statement example:
Name of employee
Hours worked
Hourly pay rate
Gross pay which is equal hours worked multiply hourly pay
rate
Federal withholding which is equal of gross pay multiply federal
tax rate
State withholdings which is equal of gross pay multiply by state
tax rate
Total deduction which is equal of federal + state
Net pay which where gross pay is minus total deduction
Below is the code in java with the output for the required task:
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
int i;
float sum=0;
float average, percentage;
Scanner scan = new Scanner(System.in);
System.out.print("Name of the employee: ");
String name= scan.nextLine();
System.out.print("Hours Worked: ");
int hours = scan.nextInt();
System.out.print("Hourly pay rate: ");
int payr = scan.nextInt();
System.out.print("Federal tax rate: ");
int ftax = scan.nextInt();
System.out.print("State tax rate: ");
int stax = scan.nextInt();
double gpay,fpay,spay,totald,net;
gpay=hours*payr;
fpay=gpay*ftax;
spay=gpay*stax;
totald=fpay+spay;
net=totald-gpay;
System.out.print("\nName of the employee: " +name);
System.out.print("\nHours Worked: " +hours);
System.out.print("\nHourly Pay Rate: " +payr);
System.out.print("\nGross Pay" +gpay);
System.out.print("\nFederal witholdings: " +fpay);
System.out.print("\nState witholdings: " +spay);
System.out.print("\nTotal deduction: " +totald);
System.out.print("\nNet Pay: " +net);
}
}
OUTPUT
Do leave an up-vote :) ask queries in comments