Foo Corporation needs a program to calculate how much to pay their hourly employ
ID: 3742795 • 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 methodsExplanation / Answer
Assumption :
Code :
package foocorporation;
import java.util.*;
class FooCorporation
{
public static float calc(float b, float h)
// The method returns the pay of the person if the base pay and the hours worked done is valid else it returns 0
{
float i = 0;
if(b<8) // checks whether the base pay is less than min
{
System.out.println("Error : Base pay less than min");
return i;
}
if(h>60) // checks is the hours worked done is more than accepted
{
System.out.println("Error : Hours worked is more than the max allowed");
return i;
}
i = h*b;
if(h > 40) // if the person has done more work then it adds up the remaining pay of the person
{
i = i + (h-40)*b/2;
}
System.out.println("The pay is : $" + i);
return i;
}
public static void main(String[] args)
{
LinkedList<Float> lList = new LinkedList<Float>(); // creating a sorted linkedList of floats
Scanner user = new Scanner( System.in ); // to take the filename of the input file
String input;
System.out.print("Input File Name: ");
input = user.nextLine().trim();
Scanner scan = new Scanner(input);
float b, h, pay; // b-> base pay... h->total hours work done.... pay-> total pay of the person
int k; // index for sorting
while(scan.hasNextFloat())
{
b = user.nextFloat();
h = user.nextFloat();
pay = calc(b,h);
if(pay>0)
{
k = 0;
while((lList.get(k)<pay)&&(k<lList.size())) // checks for the exact position for the value to be inserted
{
k++;
}
if(k==lList.size()) // when the list is empty or the value is to be put at the end
lList.add(pay);
else
lList.add(k, pay); // any other place the value is to be put
}
}
for(float p : lList)
System.out.println("$" + p);
}
}
P.S. If you could provide me with a sample input, I could help with any debugging if required .
*************NOTE*************
If there is any doubt, Please reply in the comments :)
If everything is fine, please rate accordingly :)