(Please give all the solutions and steps, if you give the answer by picture plea
ID: 3745580 • Letter: #
Question
(Please give all the solutions and steps, if you give the answer by picture please post a clear picture. Please don't answer the question if you can't do all the questions, THANKS). Answer in Java.
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. Deliverable: Eclipse ProjectExplanation / Answer
ScreenShot
------------------------------------------
Program
//Packages for file read and formatting
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.text.DecimalFormat;
//My linked list class
class linkedList {
private node head;
class node{
double val;
node link;
}
//Default constructor
public linkedList() {
head=new node();
head.val=0.0;
head.link=null;
}
//Insert into linkedlist
public boolean insert(double item) {
node x=new node();
x.val=item;
x.link=head;
head=x;
return true;
}
//Print linked list
public void print() {
node z=head.link;
while(z!=null) {
System.out.println(z.val);
z=z.link;
}
}
//sort ascending order
public boolean sortAsc() {
node x=head.link;
double c=0;
while(x.link!=null) {
node y=head.link;
while(y.link!=null) {
if(y.val>y.link.val) {
c=y.val;
y.val=y.link.val;
y.link.val=c;
}
y=y.link;
}
x=x.link;
}
return true;
}
}
//Class create with a method for pay and a main method
public class FooCorporationPayrollMain {
//Method calculate pay
public static double calculatePay(double workHours,double basicPay) {
DecimalFormat formatter = new DecimalFormat("#.##");
if(basicPay<8||workHours>60||workHours<0) {
System.out.println("Basic pay minimum is $8 and workHours not greater than 60 or less than 0");
return 0;
}
else {
if(workHours<=40) {
System.out.println("$"+formatter.format(workHours*basicPay));
return (workHours*basicPay);
}
else {
System.out.println("$"+formatter.format(((40*basicPay)+((workHours-40)*(basicPay*1.5)))));
return ((40*basicPay)+((workHours-40)*(basicPay*1.5)));
}
}
}
//Main method
public static void main(String[] args) {
double basicPay,workHours;
linkedList lst=new linkedList();
try {
//File read lie by line
File file = new File("C:/Users/deept/Desktop/fooCorporation.txt");
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
String line;
//Each line pass to evaluate function
while ((line = bufferedReader.readLine()) != null) {
String[] pair = line.split(" ");
workHours=Double.parseDouble(pair[0]);
basicPay=Double.parseDouble(pair[1]);
FooCorporationPayrollMain fp=new FooCorporationPayrollMain();
double pay=FooCorporationPayrollMain.calculatePay(workHours, basicPay);
if(pay>0.0) {
lst.insert(pay);
}
}
fileReader.close();
//Sort list
lst.sortAsc();
//Print list
System.out.println("After Sorting:");
lst.print();
} catch (IOException e) {
e.printStackTrace();
}
}
}
----------------------------------------------
Output
$550
$498
Basic pay minimum is $8 and workHours not greater than 60 or less than 0
Basic pay minimum is $8 and workHours not greater than 60 or less than 0
After Sorting:
498
550.0
-----------------------------
Myfile
50 10
41 12
62 8
37 7
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.