Question

Instructions You will be using Eclipse for all assignments in this course. You can download Eclipse from the Virtual Desktop.

Tax Bracket - Salary Tax Rate <=$250.00 18% <=$550.00 23% <=$1100.00 28% otherwise 33% o findNetIncome Takes as input the sal

employees.txt
The file has one employee per line in the following format: First line of the file: overtimeRate All other lines of the files
слол 40 38 37 13 36 N 27 29 15 25 63 12 40 37 15 33 1.3 Tao Alexander 25 Elsenpeter Bel 50 Eskro Bryan 15 Ying Charles Vue Ch

0 0
Add a comment Improve this question Transcribed image text
Answer #1

NOTE: As per the problem statement we did used the exact method descriptions. As the employee.txt is not given in text format so i used only 6 of the employee details manually put on the employee.txt, but you can run it on your system with full input file that you have.

P.S. ask for further clarification(if needed).

JAVA code for the above problem:

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

import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class AvaCam {
  
   private static double overtimeRate = 0;
   private static int count = 0;
   private static double totalPayroll = 0;
   private static double totalTaxes = 0;
   private static double payrollCheckTotal = 0;
  
   public static void userInstruct(){
        JOptionPane.showMessageDialog(new JFrame(),"This program does:\n"
               + "\nDisplay Payroll"
               + "\nWrite Payroll","Welcome",JOptionPane.INFORMATION_MESSAGE);
   }
  
   private static double findSalary(double hours, double rateOfPay, double overtimeRate){
       double salary = (hours>40)? (40)*rateOfPay : hours*rateOfPay; //base salary
       salary += (hours>40)? (hours - 40)*overtimeRate : 0;//including overtime
       return salary;
   }
  
   private static double findTaxes(double salary){
       double taxes = 0;
      
       if(salary <= 250.0) taxes = 0.18*salary;
       else if(salary <= 550.0) taxes = 0.23 * salary;
       else if(salary <= 1100.0) taxes = 0.28*salary;
       else taxes = 0.33 * salary;
      
       return taxes;
   }
  
   private static double findNetIncome(double salary, double taxes){
       return salary - taxes;
   }
  
   public static void displayPayroll(double hours, double salary, double taxes, double netIncome){
       JOptionPane.showMessageDialog(new JFrame(),"Hours: "+hours
               + "\nSalary: "+salary
               + "\nTaxed: "+taxes
               + "\nNet Come: "+netIncome,"Payroll",JOptionPane.INFORMATION_MESSAGE);
   }
  
   public static void displayPayroll(double hours, double salary, double taxes, double netIncome, double payRate, double overtimeRate){
       JOptionPane.showMessageDialog(new JFrame(),"Hours: "+hours
               + "\nPay Rate: "+payRate
               + "\nOverTime Rate: "+overtimeRate
               + "\nSalary: "+salary
               + "\nTaxed: "+taxes
               + "\nNet Come: "+netIncome,"Payroll",JOptionPane.INFORMATION_MESSAGE);
   }
  
   public static void writePayroll(double hours, double salary, double taxes, double netIncome, PrintWriter printWriter){
       printWriter.write(" "+hours+" "+salary+" "+taxes+" "+netIncome+"\n");                                                   
   }
  
   public static void writePayroll(double hours, double salary, double taxes, double netIncome, double payRate, double overtimeRate, PrintWriter printWriter){
       printWriter.write(" "+payRate+" "+overtimeRate+" "+hours+" "+salary+" "+taxes+" "+netIncome+"\n");     
   }

   public static void main(String[] args) {
       userInstruct();
      
       String num = JOptionPane.showInputDialog(new JFrame(),"Enter number of employees to be processed: ");     
      
       try {
              File myObj = new File("C:\\Users\\user\\Desktop\\employees.txt");
              PrintWriter printWriter = new PrintWriter(new File("C:\\Users\\user\\Desktop\\output_employees.txt"));
              Scanner myReader = new Scanner(myObj);
            
              overtimeRate = Double.parseDouble(myReader.nextLine().replaceAll(" ", ""));
            
              while (myReader.hasNextLine()) {
                String data = myReader.nextLine();
              
                String info[] = data.split(" ");
              
                String fname = info[0];
                String lname = info[1];
              
                double payRate = Double.parseDouble(info[2].replaceAll(" ",""));
                double hoursWorked = Double.parseDouble(info[3].replaceAll(" ",""));
//              
                System.out.println(fname+" "+lname);
              
                double salary = findSalary(hoursWorked, payRate, overtimeRate);
                double taxes = findTaxes(salary);
                double netIncome = findNetIncome(salary, taxes);
              
                displayPayroll(hoursWorked, salary, taxes, netIncome, payRate, netIncome);
              
                printWriter.write(fname+"\t"+lname);
                writePayroll(hoursWorked, salary, taxes, netIncome, payRate, netIncome, printWriter);
              
                count++;
                totalPayroll += salary;
                totalTaxes += taxes;
                payrollCheckTotal += netIncome;
              }
            
              printWriter.write("\n\nTotal number of employees processed: "+count+"\nTotal Payroll: "+totalPayroll
                      +"\nTotal Taxes: "+totalTaxes
                      + "\nTotal Payroll Checks: "+payrollCheckTotal);
            
              myReader.close();
              printWriter.flush();
              printWriter.close();
       } catch (FileNotFoundException e) {
              System.out.println("An error occurred.");
              e.printStackTrace();
       }
   }

}

The demo employee.txt:

File employees - Notepad Edit Format View Help 1.3 Tao Alexander 25 40 Elsenpeter Bel 50 38 Eskro Bryan 15 37 Ying Charles 13

The output.txt file for above input file:

The dialog box screenshots:

1. Welcome X i This program does: Display Payroll Write Payroll ОК

2. Input Х ? Enter number of employees to be processed: 61 6 OK Cancel

3. For each employee this type of dialog box is popping up as follows:fname = info[@]; lname = info[1]; AvaCam [Java Application] C:\Program Files\Java\jdk1 Tao Alexander payRate Double.parseDoub

The screenshot of above code snippets for better understanding:

import java. import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; import javax.swing.

return taxes; } 37 38 39 40 41 42 43 440 45 46 47 48 49 50 51e 52 53 54 55 56 57 58 59 60 610 private static double findNet I

710 72 73 4 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 // 94 95 96 97 98 99 100 101 102 103 104 195 public s

printWriter.write(frame+\t+Iname); writePayroll(hoursWorked, salary, taxes, netIncome, payRate, netIncome, printWriter); 10

Add a comment
Know the answer?
Add Answer to:
employees.txt Instructions You will be using Eclipse for all assignments in this course. You can download...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • By editing the code below to include composition, enums, toString; must do the following: Prompt the...

    By editing the code below to include composition, enums, toString; must do the following: Prompt the user to enter their birth date and hire date (see Fig. 8.7, 8.8 and 8.9 examples) in addition to the previous user input Create a new class that validates the dates that are input (can copy date class from the book) Incorporate composition into your class with these dates Use enums to identify the employee status as fulltime (40 or more hours worked for...

  • If the employee is a supervisor calculate her paycheck as her yearly salary / 52 (weekly...

    If the employee is a supervisor calculate her paycheck as her yearly salary / 52 (weekly pay) If the employee is not a supervisor and she worked 40 hours or less calculate her paycheck as her hourly wage * hours worked (regular pay) If the employee is not a supervisor and worked more than 40 hours calculate her paycheck as her (hourly wage * 40 ) + (1 ½ times here hourly wage * her hours worked over 40) (overtime...

  • Given attached you will find a file from Programming Challenge 5 of chapter 6 with required...

    Given attached you will find a file from Programming Challenge 5 of chapter 6 with required you to write a Payroll class that calculates an employee’s payroll. Write exception classes for the following error conditions: An empty string is given for the employee’s name. An invalid value is given to the employee’s ID number. If you implemented this field as a string, then an empty string could be invalid. If you implemented this field as a numeric variable, then a...

  • I would like help and there are three different classes in the coding.. 14.11 Prog11 Inheritance(PayrollOvertime)...

    I would like help and there are three different classes in the coding.. 14.11 Prog11 Inheritance(PayrollOvertime) Create three files to submit: • Payroll class.java -Base class definition • PayrollOvertime.jave - Derived class definition • ClientClass.java - contains main() method Implement the two user define classes with the following specifications: Payroll class (the base class) (4 pts) • 5 data fields(protected) o String name - Initialized in default constructor to "John Doe" o int ID - Initialized in default constructor to...

  • Java Programming Reading from a Text File Write a Java program that will use an object...

    Java Programming Reading from a Text File Write a Java program that will use an object of the Scanner class to read employee payroll data from a text file The Text file payroll.dat has the following: 100 Washington Marx Jung Darwin George 40 200 300 400 Kar Car Charles 50 22.532 15 30 The order of the data and its types stored in the file are as follows: Data EmployeelD Last name FirstName HoursWorked double HourlyRate Data Tvpe String String...

  • RUN THIS PROGRAM ON NETBEANS As a Software Developer, you have received a requirement from a Company to implement a prot...

    RUN THIS PROGRAM ON NETBEANS As a Software Developer, you have received a requirement from a Company to implement a prototype for its payroll system. You receive the following specifications: If an employee works more than its regular hours, it is considered overtime and it will be paid based on the employee’s experience. All employees are paid biweekly (80 hours) Employee taxes: 1% This company manages three categories of workers based on employee’s experience. Group 1 (Silver) o Pay rate:...

  • Requesting help with the following C Program: DESIGN and IMPLEMENT a menu driven program that uses...

    Requesting help with the following C Program: DESIGN and IMPLEMENT a menu driven program that uses the following menu and can perform all menu items: Enter a payroll record for one person Display all paycheck stubs Display total gross payroll from all pay records. Quit program The program will reuse the DATE struct from the previous assignment.  You should also copy in the functions relating to a DATE. The program will create a PAYRECORD struct with the following fields: typedef struct...

  • Python 3 Question Please keep the code introductory friendly and include comments. Many thanks. Prompt: The...

    Python 3 Question Please keep the code introductory friendly and include comments. Many thanks. Prompt: The owners of the Annan Supermarket would like to have a program that computes the weekly gross pay of their employees. The user will enter an employee’s first name, last name, the hourly rate of pay, and the number of hours worked for the week. In addition, Annan Supermarkets would like the program to compute the employee’s net pay and overtime pay. Overtime hours, any...

  • How would I do this problem? Write a C++ menu driven Payroll program. Must be user...

    How would I do this problem? Write a C++ menu driven Payroll program. Must be user friendly.   Menu 1. Check data file   2. Read Data file 3. Process payroll for one employee 4. Process payroll for all employees 5. Print out to a text or an HTML file 6. Exit You must use the following Payroll classes, structures, pointers, arrays, enum, vector, recursive, advance file I/O, STL, template, iterators and containers. The program to process an input file below to...

  • A) One of the problems that have been discussed in the class is to write a...

    A) One of the problems that have been discussed in the class is to write a simple C++ program to determine the area and circumference of a circle of a given radius. In this lab you will be rewriting the program again but this time you will be writing some functions to take care of the user input and math. Specifically, your main function should look like the following: int main() { double radius; double area; double circumference; //the radius...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT