-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathJava(EmpWorkAnalysis)
More file actions
66 lines (54 loc) · 1.69 KB
/
Java(EmpWorkAnalysis)
File metadata and controls
66 lines (54 loc) · 1.69 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
import java.util.*;
class Employee {
private String name;
private int[] hours;
public Employee(String name, int[] hours) {
this.name = name;
this.hours = hours;
}
public String getName() {
return name;
}
public int getTotalHours() {
int total = 0;
for (int h : hours) {
total += h;
}
return total;
}
public double getAverageHours() {
return (double) getTotalHours() / hours.length;
}
public int getOvertimeHours() {
int overtime = 0;
for (int h : hours) {
if (h > 8) {
overtime += (h - 8);
}
}
return overtime;
}
public void displayReport() {
System.out.println("----- Employee Work Report -----");
System.out.println("Name: " + name);
System.out.println("Total Hours Worked: " + getTotalHours());
System.out.println("Average Hours/Day: " + String.format("%.2f", getAverageHours()));
System.out.println("Total Overtime Hours: " + getOvertimeHours());
System.out.println("--------------------------------\n");
}
}
public class EmployeeWorkAnalysis {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter employee name: ");
String name = sc.nextLine();
int[] hours = new int[7]; // for 7 days
System.out.println("Enter hours worked for 7 days:");
for (int i = 0; i < 7; i++) {
System.out.print("Day " + (i + 1) + ": ");
hours[i] = sc.nextInt();
}
Employee emp = new Employee(name, hours);
emp.displayReport();
}
}