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

Foo Corporation needs a program to calculate how much to pay their hourly employ

ID: 3743712 • Letter: F

Question

Foo Corporation needs a program to calculate how much to pay their hourly employees. The US Department of Labor requires that employees get paid time and a half for any hours over 40 that they work in a single week. For example, if an employee works 45 hours, they get 5 hours of overtime, at 1.5 times their base pay. The State of Massachusetts requires that hourly employees be paid at least $8.00 an hour. Foo Corp requires that an employee not work more than 60 hours in a week. Summary of Rules An employee gets paid (hours worked) x (base pay), for each hour up to 40 hours For every hour over 40, they get overtime(base pay) x 1.5 The base pay must not be less than the minimum wage ($8.00 an hour). If it is, print an error If the number of hours is greater than 60, print an error message Create a new class called FooCorporation. Write a method that takes the base pay and hours worked as parameters (this data is to be read from a file), and prints the total pay or an error Write a main method that calls this method for each of these employees. The main method should also print out a sorted linked list of the pays of all employees (excluding the error entries). For this Linked List, (a) use your own code, and (b) use the LinkedList class methods

Explanation / Answer

import java.io.BufferedReader;

import java.io.File;

import java.io.FileReader;

import java.util.LinkedList;

import java.util.List;

public class FooCorporation {

static double bonusPercent = 1.5; //constants

static int maxHrs = 60;

static int limitHrs = 40;

static int minWage = 8;

public static void main(String[] args) throws Exception {

//check the file directory and create a file there

File details = new File("F:\test.txt"); //File format should have two numbers each line sep. by space :hours basepay

BufferedReader br = new BufferedReader(new FileReader(details)); // For reading the file

List<Double> wagesList = new LinkedList<>(); //List

String st;

while ((st = br.readLine()) != null) { //till the end of file

String values[] = st.split(" ");

double wage =0;

double hours = Double.parseDouble(values[0]);

double basePay = Double.parseDouble(values[1]);

if(hours>maxHrs||hours<0){ //Error condition

System.out.println("Error, hours out of limit.");

wage = -1;

}

else if(basePay<minWage){ //Error condition

System.out.println("Error, wage less than minimum wage.");

wage = -1;

}

else

wage = wageCalculator(hours,basePay);

System.out.println("The pay is " + wage); // -1 for error or add an if for neglecting it.

wagesList.add(wage); // adding in the list

}

System.out.println("The pay for the employees are "+ wagesList); //total list of wages

}

static double wageCalculator(double hours, double basePay){ //To calculate the total pay for an employee

double wage =0;

if(hours<=40){

wage = hours*basePay;

}

else{

double bonusPay = basePay*bonusPercent;

wage = limitHrs*basePay + (hours-limitHrs)*bonusPay;

}

return wage;

}

}

//I hope i was able to answer what u needed. Any question, comment. I'll get 2 u. Cheers. Dont forget //to thumbs up. :P