-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWageCalculator.java
More file actions
59 lines (46 loc) Β· 1.26 KB
/
WageCalculator.java
File metadata and controls
59 lines (46 loc) Β· 1.26 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
package BasicPractice;
public class WageCalculator {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(totalWageBasic(7.5, 35));
System.out.println(totalWageBasic(8.2, 47));
System.out.println(totalWageBasic(10.0, 73));
System.out.println("============ using correct function =============================");
System.out.println(totalWageDetailed(7.5, 35));
System.out.println(totalWageDetailed(8.2, 47));
System.out.println(totalWageDetailed(10.0, 73));
}
public static double totalWageBasic(double basePay, double hrs){
double pay;
if (basePay>8 && hrs<60){
if (hrs>40){
pay = hrs * (1.5 * basePay);
return pay;
}else{
pay = hrs * basePay;
return pay;
}
}else{
return -1;
}
}
public static double totalWageDetailed(double hrs, double basePay){
if (basePay<8.0){
System.out.println("You must be paid at least $8.0 per hour");
return -1;
}else if(hrs>60){
System.out.println("You cannot work more than 60 hours per week");
return -1;
}else{
double pay = 0.0;
double overtimeHours = 0;
if (hrs>40){
overtimeHours = hrs - 40;
hrs = 40;
}
pay = hrs * basePay;
pay += hrs * 1.5 * overtimeHours;
return pay;
}
}
}