Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java question: employee payroll system * enter employee\'s name * enter employee

ID: 3698160 • Letter: J

Question

Java question: employee payroll system

* enter employee's name

* enter employee's base hourly pay

* enter the number of hours worked for the week

* error if hours worked exceeds 168 hours

* determine if employee is full-time or part-time

* use the following:

*****federal tax 3.5%

*****state tax 1.75%

*****social security 5%

*****health ins $100.00

*****dental ins $30.00

*****retirement 8%

if hours work is less than 40 then do not deduct health ins, dental ins, and retirement should be 4%

**use loop to enter additional employee's information until you enter keyword of "Exit" in employee's name-which should also terminate program

** use both if(if/else) and case code to make decisions based on program

** output should result to output file of SalaryInformaion.txt

Explanation / Answer

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;

public class Payroll {
  
   public static void main(String[] args) throws IOException {
      
       InputStreamReader isr = new InputStreamReader(System.in);
       BufferedReader sc = new BufferedReader(isr);
       String name;
       double hourly_pay;
       int hours;
       boolean employeeType;
      
       double totalPay = 0;
      
       FileWriter fw = new FileWriter("SalaryInformaion.txt");
       BufferedWriter bw = new BufferedWriter(fw);
      
       while(true){
           System.out.print(" Enter Employee Name: ");
           name = sc.readLine();
          
           if("exit".equalsIgnoreCase(name))
               break;
           System.out.print("Enter hourly pay rate: ");
           hourly_pay = Double.parseDouble(sc.readLine());
          
           System.out.print("Enter number of hours: ");
           hours = Integer.parseInt(sc.readLine());
          
           while(hours > 168){
               System.out.println("Number of hours should be less than or equal to 168 ");
               hours = Integer.parseInt(sc.readLine());
           }
          
           System.out.print("Are you full time employee ? ");
           employeeType = Boolean.parseBoolean(sc.readLine());
          
           totalPay = hourly_pay*hours;
          
           double federal_tax = totalPay*0.035;
           double state_tax = totalPay*0.0175;
           double social_security_tax = totalPay*0.05;
          
           double health = 100;
           double dental = 30;
           double retirement = totalPay*0.08;
          
           if(hours < 40){
               health = 0;
               dental = 0;
               retirement = totalPay*0.04;
           }
          
           totalPay = totalPay - (federal_tax+state_tax+social_security_tax+health+dental+retirement);
          
           bw.write(name+" total amount: "+String.format("%.3f", totalPay));
          
           System.out.println(name+" total amount: "+ totalPay);
          
       }
       System.out.println("Data has also writen to file");
       bw.close();
   }

}

/*

Output:


Enter Employee Name: Pravesh Kumar
Enter hourly pay rate: 2300
Enter number of hours: 160
Are you full time employee ? true
Pravesh Kumar total amount: 300710.0

Enter Employee Name: Alex Bob
Enter hourly pay rate: 2400
Enter number of hours: 190
Number of hours should be less than or equal to 168
120
Are you full time employee ? true
Alex Bob total amount: 235310.0

Enter Employee Name: exit
Data has also writen to file

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote