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

JAVA programming through eclipse. This is an introduction class so the code is f

ID: 3605349 • Letter: J

Question

JAVA programming through eclipse. This is an introduction class so the code is fairly simple.

Write a payroll processing program. Input will be from a file called “weeklyData.txt”. You may create this file on your own for testing purposes. Each line in the file contains information about one employee. Each item is separated by a space. The items are, in order:

First Name

Last Name

Hourly wage rate (decimal)

Hours

worked (decimal)

# of dependents (whole number)

% of gross retirement (whole number, ranges from 0 to 10)

Amount donated to United Way (dollar amount)

For each employee listed in this file, read the above data and produce the following detail data:

Regular hours worked and overtime hours worked

Regular pay and overtime pay and gross pay

Pension contribution, United Way contribution

Taxable income

Insurance deduction and Income tax deduction

Net pay

Calculations:

Overtime hours are all hours over 40, the rest are regular hours

Regular pay is the regular hours times the wage rate

Overtime pay is 1.5 times the overtime hours times the wage rate

Gross pay is regular pay plus overtime pay

Retirement is the percentage of the gross deducted from the employee

United Way contribution is whatever was read

Taxable income is gross minus both the retirement and united way contributions

Insurance is determined by the number of dependents:

0 is $25.19

1 is $39.02

2 or more is $50.63

Income tax is calculated on taxable income as follows:

The first $300 dollars is not taxed

The next $500 is taxed at 5% of gross

Everything over $800 is taxed at 8.5% of gross

Net pay is gross pay minus the two deductions (retirement, united way, tax and insurance)

The detail output should be to a file called “payroll.txt” formatted nicely, and include the three input

values as well as all calculated values. Separate each employee’s detail data in the file as you see fit

Summary data should include the following (and should be printed at the end of the detail data in the output file, as well as to the screen

# of employees

Total payroll (sum of all gross pay), and of that how much was overtime

Total hours worked, and of that how many were overtime hours

Total retirement contributions

Total United Way contributions

Total insurance premiums

Total taxes withheld

Explanation / Answer

import java.util.Scanner;

  public class Payroll {

    public static void main(String[] args) {

        Scanner input = new Scanner ( System.in );

        double hourlyRate;

        double hoursWorked;

        double grossPay; // Calculated weekly pay before taxes

        double taxDeduction; // gross pay * 14%

        double netPay; // Calculated weekly pay after taxes

         

        System.out.print("Employee name: ");

        String employeeName = input.nextLine();

        System.out.printf("Enter hourly rate for %s: $", employeeName);

        hourlyRate = input.nextDouble();

        while(hourlyRate < 0.00){

        System.out.print("Please enter only a positive number: $");

        hourlyRate = input.nextDouble();

        }

        System.out.printf("total hours worked: ");

        hoursWorked = input.nextDouble();

        while (hoursWorked < 0.00){

        System.out.print("Please enter only a positive number: ");

        hoursWorked = input.nextDouble();

        }

        grossPay = hourlyRate * hoursWorked;

        System.out.printf("gross pay: $%.2f ", grossPay);

        System.out.println();

         

        taxDeduction = grossPay * .14;

        System.out.printf("federal taxes: $%.2f ", taxDeduction);

        System.out.println();

         

        netPay = grossPay - taxDeduction;

        System.out.printf("net pay: $%.2f ", netPay);

        System.out.println();

         

        input.nextLine();

        System.out.print("Employee name:"); // Loops back to start

        employeeName = input.nextLine();

        }

        } [code]

the second variation is where i am having trouble i need to incorperate a overtime calculation into it which i was able to do but now it is not calculating any taxes being with held... the code is as follows....

[code] import java.util.Scanner; // import delcaration for program to use class Scanner

import java.text.NumberFormat;

import java.text.DecimalFormat;

import java.util.Scanner;

public class payrollattempt

{

     // main method begins execution of Java application

     public static void main( String args[] )

     {

         Scanner input = new Scanner( System.in ); // create Scanner to obtain input from the command window

  

         boolean stop = false;

  

         String cleanInputBuffer; // input

         String getName;

         double hoursWorked; // variable for the employee's hours worked

         double hourlyRate; // variable for the employee's hourly rate

         double grossPay; // Calculated weekly pay before taxes

         double taxDeduction; // gross pay * 14%

         double netPay; // Calculated weekly pay after taxes

         double overTime;

  

         while(stop== false)

         {

  

         System.out.print("Enter employees Name or 'quit' to exit: "); // prompt

         getName = input.nextLine(); // read employee's name

             if(getName.equalsIgnoreCase ( "quit" ) ) // condition statement to request data until stop is entered

             {

            System.out.print("Exiting Payroll Program. "); // prompt

             stop = true;

             }

  

                 else

                 {

                     System.out.print("Enter Hourly Rate: ");

                     hourlyRate = input.nextDouble(); // read hourly rate

  

                         while ( hourlyRate < 0 ) // condition statement to check for negative number

                         {

  

                             System.out.print("Enter the hourly rate of pay for the employee: "); // prompt

                             hourlyRate = input.nextDouble(); // read hourly rate

                         } // end while

  

             System.out.print("Enter the hours worked by employee this week: "); // prompt

             hoursWorked = input.nextDouble(); // read hours worked

  

                 while ( hoursWorked < 0 ) // condition statement to check for negative number

                 {

                     System.out.println("Error: You have entered a negative number!"); // error message

                     System.out.print("Enter the hours worked by employee this week: "); // prompt

                     hoursWorked = input.nextDouble(); // read hours worked

                 } // end while

         if (hoursWorked > 40)// Overtime

  

         {

  

         grossPay = hoursWorked * hourlyRate;//multiplication

         overTime = (hoursWorked-40) * (hourlyRate*1.5);

         taxDeduction = grossPay * .14;

         System.out.printf("federal taxes: $%.2f ", taxDeduction);

         System.out.println();

         

         netPay = grossPay - taxDeduction;

         System.out.printf("net pay: $%.2f ", netPay);

         System.out.println();

  

         System.out.println("Employee:" + getName);

         System.out.printf("Hourly Rate: $%.2f ", hourlyRate);

         System.out.println("Regular Hours worked:" + "40");

         System.out.println("Overtime Hours worked:" + (hoursWorked-40));

         System.out.printf("Total Pay: $%.2f ", netPay);

         System.out.printf("Overtime Pay: $%.2f ", overTime);

         System.out.printf("Gross Pay: $%.2f ", netPay+overTime);

         }

             else                // Under 40 Hours

             {

             netPay = hoursWorked * hourlyRate;

             System.out.println("Employee:" + getName);

             System.out.printf("Hourly Rate: $%.2f ", hourlyRate);

             System.out.println("Regular Hours worked:" + hoursWorked);

             System.out.printf("Gross Pay: $%.2f ", netPay);

             }

  

             System.out.printf( "Enter employee name or 'quit' to exit:");

             getName = input.next();

  

             cleanInputBuffer = input.nextLine();

  

         }

     } // end method main

  

} // end class Part2