(Compute the weekly hours of each employee and their gross pay) Suppose we have
ID: 660923 • Letter: #
Question
(Compute the weekly hours of each employee and their gross pay) Suppose we have a small company with eight employees. The weekly hours for all the employees are shown below. Each row records an employee's seven day work hours with seven columns. The pay rate for each employee is given below: Pay rate $16.25 $15.96 $22.00 $30.50 $15.64 $18.75 $26.42 $22.50 Write a function loadData that will load the values into the program Write a function getTotal that will return the total hours for each employee Write a function grossPay that will calculate the gross pay for each employee. If the employee's hours are over 40, the gross pay = 40 * rate + (total hours - 40)* 1.5*rate. The program should print the employee name, total hours and the gross pay. Also, it should print them in order from the smallest gross pay to the largest.Explanation / Answer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.util.Scanner;
public class WeeklyHour
{
public static int[][] readHours()
{
Scanner scan = new Scanner (System.in);
int[][] employees = new int[8][7];
for (int i =0;i<employees.length;i++)
{
for (int j =0;j<employees[i].length;j++)
{
employees[i][j] = scan.nextInt();
}
}
return employees;
}
public static int[][] sortEmployees(int[][] employees)
{
int[][] tempar = new int[8][2];
for (int i =0;i<employees.length;i++)
{
tempar[i][0] =i;
for (int j=0;j<employees[i].length;j++)
{
tempar[i][1] += employees[i][j];
}
}
for (int i =0;i<employees.length;i++)
{
for (int j =0;j<employees.length -1;j++)
{
if ( tempar[j][1] < tempar[j+1][1] )
{
int temp = tempar[j][1];
int temp2 = tempar[j][0];
tempar[j][1] = tempar[j+1][1];
tempar[j][0] = tempar[j+1][0];
tempar[j+1][1] = temp;
tempar[j+1][0] = temp2;
}
}
}
return tempar;
}
public static void printEmployees(int[][] tempar)
{
for (int i =0;i<tempar.length;i++)
{
System.out.println("Employee's " + tempar[i][0] +
" worked the most with " + tempar[i][1] + " hours" );
}
}
public static void main (String[] args)
{
int[][] nums = readHours();
int[][] nums1 = sortEmployees(nums);
printEmployees(nums1);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.util.Scanner;
public class WeeklyHour
{
public static int[][] readHours()
{
Scanner scan = new Scanner (System.in);
int[][] employees = new int[8][7];
for (int i =0;i<employees.length;i++)
{
for (int j =0;j<employees[i].length;j++)
{
employees[i][j] = scan.nextInt();
}
}
return employees;
}
public static int[][] sortEmployees(int[][] employees)
{
int[][] tempar = new int[8][2];
for (int i =0;i<employees.length;i++)
{
tempar[i][0] =i;
for (int j=0;j<employees[i].length;j++)
{
tempar[i][1] += employees[i][j];
}
}
for (int i =0;i<employees.length;i++)
{
for (int j =0;j<employees.length -1;j++)
{
if ( tempar[j][1] < tempar[j+1][1] )
{
int temp = tempar[j][1];
int temp2 = tempar[j][0];
tempar[j][1] = tempar[j+1][1];
tempar[j][0] = tempar[j+1][0];
tempar[j+1][1] = temp;
tempar[j+1][0] = temp2;
}
}
}
return tempar;
}
public static void printEmployees(int[][] tempar)
{
for (int i =0;i<tempar.length;i++)
{
System.out.println("Employee's " + tempar[i][0] +
" worked the most with " + tempar[i][1] + " hours" );
}
}
public static void main (String[] args)
{
int[][] nums = readHours();
int[][] nums1 = sortEmployees(nums);
printEmployees(nums1);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.