-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeaveManagementSystem.java
More file actions
117 lines (98 loc) · 5.06 KB
/
LeaveManagementSystem.java
File metadata and controls
117 lines (98 loc) · 5.06 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import java.util.ArrayList;
import java.util.Scanner;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
interface iLeaveManagementSystem {
void leaveManagementSystem(AddEmployee empInfo, Employee emp);
}
class Employee {
int totalLeaves; int leavesTaken; int deductionAmount;
public Employee() {
this.totalLeaves = 5; // Total leaves allowed without deduction
this.leavesTaken = 0;
this.deductionAmount = 0;
}
}
class LeaveManagementSystem implements iLeaveManagementSystem {
public void leaveManagementSystem(AddEmployee empInfo, Employee emp) {
Scanner s = new Scanner(System.in);
int choice;
do {
System.out.println("\nLEAVE MANAGEMENT SYSTEM MENU:");
System.out.println("1. Apply for Leave");
System.out.println("2. Display Leave Record");
System.out.println("3. Exit");
System.out.print("Enter your choice: ");
choice = s.nextInt();
switch (choice) {
case 1:
applyForLeave(empInfo, emp);
break;
case 2:
displayLeaveRecord(empInfo, emp);
break;
case 3:
break;
default:
System.out.println("Invalid choice. Please enter a valid option.");
}
} while (choice != 3);
System.out.println("\nX-------------------------X-------------------------------X\n");
System.out.println("Exiting Leave Management System...");
}
public void applyForLeave(AddEmployee empInfo, Employee employee) {
boolean empFound = false;
Scanner s = new Scanner(System.in);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
System.out.println("\nAPPLY FOR LEAVE\n");
System.out.print("Enter Employee Number for which you want to apply leave: ");
String inputEmpNum = s.nextLine();
for (int i = 0; i < empInfo.addEmp.size(); i++) {
if (inputEmpNum.equals(empInfo.addEmp.get(i).employeeNum)) {
System.out.println("\nEmployee found!\n");
System.out.print("Enter leave from (DD-MM-YYYY): ");
String inputFromDate = s.nextLine();
LocalDate fromDate = LocalDate.parse(inputFromDate, formatter);
System.out.print("Enter leave till (DD-MM-YYYY): ");
String inputToDate = s.nextLine();
LocalDate toDate = LocalDate.parse(inputToDate, formatter);
// Calculate total leave days
int totalLeaveDays = (int) ChronoUnit.DAYS.between(fromDate.minusDays(1), toDate) + 1;
// Deduction logic for leaves beyond the allowed limit
if (totalLeaveDays > employee.totalLeaves) {
int extraLeaves = totalLeaveDays - employee.totalLeaves;
employee.deductionAmount += extraLeaves * 1000;
totalLeaveDays = employee.totalLeaves; // Cancel extra leaves beyond the allowed limit
System.out.println("Deduction Amount: Rs. " + employee.deductionAmount);
}
// Update employee's leave information
employee.leavesTaken += totalLeaveDays;
System.out.println("\nX-------------------------X-------------------------------X\n");
System.out.println("Leave applied successfully...");
System.out.println("Returning to Leave Management System Menu...\n");
empFound = true;
break;
}
}
}
public void displayLeaveRecord(AddEmployee empInfo, Employee employee) {
Scanner s = new Scanner(System.in);
System.out.println("DISPLAY LEAVE RECORD\n");
System.out.print("Enter Employee Number for which you want to display leave record: ");
String inputEmpNum = s.nextLine();
for (int i = 0; i < empInfo.addEmp.size(); i++) {
if (inputEmpNum.equals(empInfo.addEmp.get(i).employeeNum)) {
System.out.println("\nEmployee found!\n");
System.out.println("Leave Record for Employee: " + empInfo.addEmp.get(i).employeeName);
System.out.println("Employee Number: " + empInfo.addEmp.get(i).employeeNum);
System.out.println("Total Leaves Allowed: " + employee.totalLeaves);
System.out.println("Leaves Taken: " + employee.leavesTaken);
System.out.println("Deduction Amount: Rs. " + employee.deductionAmount);
System.out.println("Unpaid Leaves Allowed: " + Math.max(0, employee.totalLeaves - employee.leavesTaken));
}
}
System.out.println("\nX-------------------------X-------------------------------X\n");
System.out.println("Returning to Leave Management System Menu...\n");
}
}