-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSalaryCal.java
More file actions
51 lines (34 loc) · 1.58 KB
/
SalaryCal.java
File metadata and controls
51 lines (34 loc) · 1.58 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
import java.util.*;
public class SalaryCal {
public static Scanner sc = new Scanner(System.in); // a scanner to be called
public static double answer; // The final solve-for
public static void main(String[] args) {
sc.useDelimiter(",");
System.out.println("Type full name of employee, the base pay, and hours he/she worked." );
System.out.println("<(Ex) David Kane,9.81,46,> "); //Additional info for user to use
System.out.println("[※Note: ★No spaces before/after comma ★Put comma at the end also]"); // Avoid errors
String fullName = sc.next();
double pay = sc.nextDouble();
double hour = sc.nextDouble(); //collect datas to input in salarayTotal method
answer = salaryTotal(pay,hour); //last step
if (answer == -1)
System.out.println("The base salary you entered does not comply with the state law");
else if (answer == -2)
System.out.println("The number of hours your entered does not comply with company policy");
else
System.out.printf("The total pay for <%s> is <%.2f> dollars", fullName, answer);
}
public static double salaryTotal(double basePay, double hoursWorked) { //2 inputs : base pay & hours worked in a week
double salary; //the one that will be returned
double overtime = hoursWorked - 40; // created for else if statement
if (basePay < 5.24)
return -1;
if (hoursWorked > 60)
return -2;
else if (hoursWorked > 40)
salary = (overtime * (basePay*1.5)) + ((hoursWorked-overtime)*basePay);
else
salary = hoursWorked * basePay;
return salary;
}
}