Question

In: Computer Science

Changes from the basic are highlighted yellowWrite a payroll processing program. Input will be from...

Changes from the basic are highlighted yellow
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, but I have provided a file with 75 employees that I will use to test your code. (I know what it should produce).
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 withheld for 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, 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, and the company will donate a matching amount up to $100.00. The matching amount is not added to the employees pay, or deducted from their pay. Just note this amount when you print the detail data for retirement. 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 8.5% of gross Everything over $800 is taxed at 12.5% of gross

with the following stipulation: for each dependent, the tax rates (8.5 and 12.5) are reduced by %0.5 (a half of a percent). So, if a person has 2 dependents the rates would be %7.5 and %11.5

Net pay is gross pay minus the four 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 and total amount of matching funds Total United Way contributions Total insurance premiums Total taxes withheld

Solutions

Expert Solution

Please find my implementation.

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class ProjectFive {

   public static void main(String[] args) throws IOException {
       // Payroll Project
       Scanner inFile = new Scanner(new File("weeklyData.txt"));
       PrintWriter outFile = new PrintWriter(new File("payroll.txt"));

       int counter1 = 0;
       double counter2 = 0;
       double counter4 = 0;
       double counter5 = 0;
       double counter6 = 0;
       double counter7 = 0;
       double counter8 = 0;
       while (inFile.hasNext()) {

           String name1 = inFile.next();
           String name2 = inFile.next();
           double hourly = inFile.nextDouble();
           double worked = inFile.nextDouble();
           int dependants = inFile.nextInt();

           double ins = calcInsurance(dependants);
           double gross = calcGross(worked, hourly);
           double overtime3 = calcOvertime(worked);
           double overtime2 = calcOTPay(worked, hourly);
           double tax = calcTax(gross);
           double reg = worked - overtime3;

           counter1++;
           counter2 += worked;
           counter4 += gross;
           counter5 += overtime3;
           counter6 += overtime2;
           counter8 += ins;
           counter7 += tax;
           System.out.printf("Hours Worked: (Regular:%.2f Overtime:%.2f) total hours %.2f Total overtime %.2f %n", reg,
                   overtime3, counter2, counter5);
       }

   }

   public static double calcOvertime(double worked) {
       if (worked > 40) {
           return (worked - 40);
       }
       return 0;
   }

   public static double calcOTPay(double worked, double hourly) {
       if (worked > 40) {
           return ((worked - 40) * hourly * 1.5);
       }
       return 0;
   }

   public static double calcTax(double gross) {
       if (gross <= 300) {
           return 0;
       } else if (gross <= 800) {
           return ((gross - 300) * .05);
       } else if (gross > 800) {
           return ((gross - 800) * .085) + ((800 - 300) * .05);
       } // Unneeded final return but function fails without

       return gross;
   }

   public static double calcInsurance(int dependants) {
       if (dependants == 0) {
           return 25.19;
       } else if (dependants == 1) {
           return 39.02;
       } else if (dependants >= 2) {
           return 50.63;
       } // Unneeded final return but function fails without

       return dependants;
   }

   public static double calcGross(double worked, double hourly) {
       if (worked > 40) {
           return (40 * hourly) + ((worked - 40) * hourly * 1.5);
       } else {
           return worked * hourly;
       }

   }

}
/*
weeklyData.txt

Randy Rich 32.32 46.75 5
Ruby Bianchi 21.94 40.00 2
Clemens Hopkins 18.18 39.50 1
Hugo Shannon 18.52 40.00 0
Carol Carpenter 24.54 39.00 5
Gero Parker 31.36 40.00 5
Otto Muniz 37.45 48.75 5
Gordon Uzarski 42.95 40.00 4
Tina Lee 15.25 40.00 2
Calvin Harper 39.95 40.00 0
Kelvin Fowler 37.45 40.00 1
Freddy Hobbs 41.11 38.25 0
Clayton Frank 27.18 36.50 2
Edward Harris 19.40 45.00 4
Shea Torres 31.19 49.75 4
Ruben Aguilar 41.54 40.00 0
Betty Wiggins 17.43 40.00 1
Gabriel Hall 23.62 34.00 4
Zina Dominguez 40.44 39.00 4
Alfredo Castellena 35.63 38.75 4
Archie Turner 41.55 40.00 0
Ernest Phillips 17.49 40.00 3
Carlton Neto 26.10 48.50 1
Grace Pitts 30.41 35.00 0
Abraham Knox 20.17 40.00 2
Randy Boyd 34.92 40.00 1
Max Zimmerman 22.31 40.00 0
Homer Harper 34.56 40.00 1
Mauritius Gray 32.93 40.00 3
Arturo Lawrence 26.44 40.00 4
Fernando Pittman 22.94 40.00 4
Kenneth Hernandez 37.53 40.00 1
Eugene Adgate 34.99 40.00 1
Werner Halpin 40.39 47.50 2
Dan O'Flanigan 21.95 38.75 1
Linda Sun 40.61 45.25 1
Gregor Neal 21.94 40.00 2
Hugh Dominguez 33.54 50.75 1
Helen Goodman 30.36 40.00 3
Dwight Monroe 29.79 34.75 0
Helena Mcgee 32.31 45.75 3
Melvin Stanley 43.07 39.75 1
Agnes Martinez 21.73 47.75 4
Filbert Bethel 33.49 40.00 3
Herman Carter 36.16 40.00 4
Felix Hudson 36.11 40.00 2
Ben Cohen 31.69 48.25 2
Wayne Navarro 35.54 34.75 1
Frank Johnson 37.62 36.00 3
Edward Greer 43.29 40.00 4
Nicole Todd 28.96 40.00 2
Alvin Asmal 18.70 40.00 1
Debra Curry 39.30 40.00 1
Julius Bankemper 34.91 38.00 0
Johnny Rios 41.96 37.25 3
Harvey Simon 21.64 40.00 4
Anthony Walton 41.52 36.25 1
Terrance Morgan 26.86 40.00 4
Mitchell Mersey 41.50 40.00 2
Frank Rios 27.96 34.50 3
Neal Williamson 34.10 40.00 0
Casey Hansen 27.97 49.25 3
Perry Roth 20.57 40.00 3
Kenny Beck 25.04 40.00 5
Betty Davis 39.97 49.00 1
Ed Cruz 21.82 38.00 3
Margareta Serrano 15.10 40.00 1
Agatha Roman 28.33 38.75 1
Colleen Skolnik 22.18 40.00 1
Ronnie Roux 19.12 40.00 1
Quincy Peters 34.58 40.00 0
Benedikt Yates 16.15 48.25 1
Enrique Carpenter 34.97 36.25 4
Janet Visser 44.00 45.50 3
Alan Rodriguez 20.53 40.00 4
*/


Related Solutions

Identify and explain the three basic functions of system: Input" Processing and output?
Identify and explain the three basic functions of system: Input" Processing and output?
Indicate whether the following represent IT input controls, processing controls, or output controls. •In the payroll...
Indicate whether the following represent IT input controls, processing controls, or output controls. •In the payroll system, work hours entered for a single employee for a week cannot exceed 70. •In the purchasing system, list of vendor checks printed is scanned by the controller before checks are mailed. •In a sales system, invoices would not be printed if total revenue doesn't match quantity times sales price. •In the purchasing system, vendor invoices cannot be entered if the vendor name doesn't...
JAVA Assignment: Project File Processing. Write a program that will read in from input file one...
JAVA Assignment: Project File Processing. Write a program that will read in from input file one line at a time until end of file and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by either whitespace, a period, a comma or the beginning or end of the line. You can assume that the input consists entirely of...
1. Identify and explain the three basic functions of system: Input, Processing, and Output? 2. In...
1. Identify and explain the three basic functions of system: Input, Processing, and Output? 2. In details, explain the two types of software?
Write a basic C++ program with function, whose input is a character and a string, and...
Write a basic C++ program with function, whose input is a character and a string, and whose output indicates the number of times the character appears in the string. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z Today is Monday the output is: 0 Ex: If the input is: n It's a sunny day the output is: 2 Case matters. n is different than N. Ex: If the input is: n...
Dorsey Company manufactures three products from a common input in a joint processing operation. Joint processing...
Dorsey Company manufactures three products from a common input in a joint processing operation. Joint processing costs up to the split-off point total $350,000 per quarter. For financial reporting purposes, the company allocates these costs to the joint products on the basis of their relative sales value at the split-off point. Unit selling prices and total output at the split-off point are as follows: Product Selling Price Quarterly Output A $ 20.00 per pound 13,000 pounds B $ 14.00 per...
Dorsey Company manufactures three products from a common input in a joint processing operation. Joint processing...
Dorsey Company manufactures three products from a common input in a joint processing operation. Joint processing costs up to the split-off point total $335,000 per quarter. For financial reporting purposes, the company allocates these costs to the joint products on the basis of their relative sales value at the split-off point. Unit selling prices and total output at the split-off point are as follows: Product Selling Price Quarterly Output A $ 17.00 per pound 12,400 pounds B $ 11.00 per...
Dorsey Company manufactures three products from a common input in a joint processing operation. Joint processing...
Dorsey Company manufactures three products from a common input in a joint processing operation. Joint processing costs up to the split-off point total $380,000 per quarter. For financial reporting purposes, the company allocates these costs to the joint products on the basis of their relative sales value at the split-off point. Unit selling prices and total output at the split-off point are as follows: Product Selling Price Quarterly Output A $ 26.00 per pound 14,200 pounds B $ 20.00 per...
Dorsey Company manufactures three products from a common input in a joint processing operation. Joint processing...
Dorsey Company manufactures three products from a common input in a joint processing operation. Joint processing costs up to the split-off point total $97,000 per quarter. The company allocates these costs to the joint products on the basis of their relative sales value at the split-off point. Unit selling prices and total output at the split-off point are as follows: Product Selling Price Quarterly Output A $ 4 per pound 14,000 pounds B $ 5 per pound 19,000 pounds C...
Dorsey Company manufactures three products from a common input in a joint processing operation. Joint processing...
Dorsey Company manufactures three products from a common input in a joint processing operation. Joint processing costs up to the split-off point total $320,000 per quarter. For financial reporting purposes, the company allocates these costs to the joint products on the basis of their relative sales value at the split-off point. Unit selling prices and total output at the split-off point are as follows: Product Selling Price Quarterly Output A $ 14.00 per pound 11,800 pounds B $ 8.00 per...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT