+1 (315) 557-6473 

Program To Calculate Total Hours of Employees in Java Language Assignment Solution.


Instructions

Objective
Write a java assignment program to calculate total hours of employees.

Requirements and Specifications

The array below shows the number of hours an employee has worked each week for 26 weeks.
Write code to compute and print:
The number of weeks the employee worked overtime (more than 40 hours).
The total number of overtime hours accumulated.
If the regular pay = $25 per hour, find the total gross pay after 26 weeks (time and half for more than 40 hours of work, no penalty for sick/vacation time).
          int []hours = {40, 48, 40, 40, 32, 40, 45, 40, 40, 42, 28, 40, 45, 40, 40, 40, 50, 45, 48, 40, 32, 28, 40, 40, 45, 40};
Using the following tax rates, compute the total taxes paid after 26 weeks.
Gross Pay
Tax rate
0 to $1100
5%
$1101 and above
7%
Source Code
public class App {
    public static void main(String[] args) throws Exception {
        // Array with hours
        int[] hours = {40, 48, 40, 40, 32, 40, 45, 40, 40, 42, 28, 40, 45, 40, 40, 40, 50, 45, 48, 40, 32, 28, 40};
        // Count number of week that the employee worked overtime
        int weeks_overtime = 0;
        int overtime_hours = 0;
        double regular_pay = 25;
        double overtime_pay = 1.5*regular_pay;
        double gross_pay = 0.0;
        double taxes = 0.0;
        double net_pay;
        for(int i = 0; i < hours.length; i++)
        {
            if(hours[i] > 40)
            {
                weeks_overtime++;
                overtime_hours += hours[i];
                gross_pay += regular_pay*40 + overtime_pay*(hours[i]-40);
            }
            else
                gross_pay += regular_pay*hours[i];
        }
        // Calculate taxes
        if(gross_pay > 1100)
            taxes = 0.07*gross_pay;
        else
            taxes = 0.05*gross_pay;
        net_pay = gross_pay - taxes;
        // Print
        System.out.printf("%10s:%11.4f\n", "Gross Pay", gross_pay);
        System.out.printf("%10s:%11.4f\n", "Taxes", taxes);
        System.out.printf("%10s:%11.4f\n", "Net Pay", net_pay);
    }
}