package pom;
import java.util.ArrayList;
import java.util.Scanner;
class FactoryAccessControlSystem {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
ArrayList<Employee> employees = new ArrayList<>();
// 将员工对象添加到员工列表
employees.add(new Employee("aa", "b", 1, 10));
employees.add(new Employee("bb", "d", 2, 5));
System.out.print("Enter employee first name: ");
String firstName = input.nextLine();
System.out.print("Enter employee last name: ");
String lastName = input.nextLine();
System.out.print("Enter floor number: ");
int floorNumber = input.nextInt();
// 检查员工是否可以进入楼层
boolean accessGranted = false;
for (Employee employee : employees) {
if (employee.getFirstName().equals(firstName) && employee.getLastName().equals(lastName)) {
if (floorNumber >= employee.getMinFloor() && floorNumber <= employee.getMaxFloor()) {
accessGranted = true;
}
}
}
if (accessGranted) {
System.out.println("Access granted.");
} else {
System.out.println("Access denied.");
}
}
}
class Employee {
private final String firstName;
private final String lastName;
private final int minFloor;
private final int maxFloor;
public Employee(String firstName, String lastName, int minFloor, int maxFloor) {
this.firstName = firstName;
this.lastName = lastName;
this.minFloor = minFloor;
this.maxFloor = maxFloor;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public int getMinFloor() {
return minFloor;
}
public int getMaxFloor() {
return maxFloor;
}
}
【无标题】门禁员工管理系统(源码)
最新推荐文章于 2024-10-23 10:31:13 发布
该代码示例是一个基于Java的简单楼层访问控制系统。程序使用Scanner获取用户输入的员工姓名和要访问的楼层号,然后遍历Employee对象列表,检查员工是否有权限进入指定楼层。如果员工的名字匹配且楼层号在员工的允许范围内,系统批准访问;否则,拒绝访问。
1039





