-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHourlySalary.java
More file actions
80 lines (72 loc) · 2.82 KB
/
HourlySalary.java
File metadata and controls
80 lines (72 loc) · 2.82 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* Programmer: Dan Hopp
* Date: 20-NOV-2019
* Description:
• Define a static method called printSalary to print hourly salaries. The
printSalary method should take a double array as an input.
• Define an instance method called averageSalary to return average hourly
salary.
• Define an instance method called highestSalary to print the highest
hourly salary.
• Define an instance method called lowestSalary to print the lowest hourly
salary.
• Define an instance method called belowAverageSalary to return the number
of employees with less than the average hourly salary.
*/
package lab8;
public class HourlySalary {
//default constructor
public HourlySalary(){
}
//Static method called printSalary to print hourly salaries. The
//printSalary method should take a double array as an input.
public static void printSalary(double[] salaries){
System.out.println("The hourly salaries are: ");
for(int i = 0; i < salaries.length; i++){
System.out.printf("$%4.2f ", salaries[i]);
}
//new line
System.out.println();
}
//Instance method called averageSalary to return average hourly salary
public double averageSalary(double[] salaries){
double sum = 0;
for(int i = 0; i < salaries.length; i++){
sum+= salaries[i];
}
return sum / salaries.length;
}
//Instance method called highestSalary to print the highest hourly salary
public void highestSalary(double[] salaries){
double highestSalary = salaries[0];
for(int i = 1; i < salaries.length; i++){
if(salaries[i] > highestSalary){
highestSalary = salaries[i];
}
}
System.out.printf("The highest hourly salary is $%4.2f.\n",
highestSalary);
}
//Instance method called lowestSalary to print the lowest hourly salary
public void lowestSalary(double[] salaries){
double lowestSalary = salaries[0];
for(int i = 1; i < salaries.length; i++){
if(salaries[i] < lowestSalary){
lowestSalary = salaries[i];
}
}
System.out.printf("The lowest hourly salary is $%4.2f.\n",
lowestSalary);
}
//Instance method called belowAverageSalary to return the number
//of employees with less than the average hourly salary
public int belowAverageSalary(double[] salaries, double averageSalary){
int belowAverageCount = 0;
for(int i = 0; i < salaries.length; i++){
if(salaries[i] < averageSalary){
belowAverageCount++;
}
}
return belowAverageCount;
}
}