用Java写一个人脸识别的酒店管理系统
时间: 2023-06-13 15:03:58 浏览: 152
Java写的酒店管理系统
5星 · 资源好评率100%
好的,以下是一个简单的人脸识别的酒店管理系统的Java代码示例:
```java
import java.util.ArrayList;
import java.util.Scanner;
public class HotelManagementSystem {
private ArrayList<Guest> guests;
public HotelManagementSystem() {
guests = new ArrayList<>();
}
public void addGuest(Guest guest) {
guests.add(guest);
}
public void removeGuest(Guest guest) {
guests.remove(guest);
}
public void listGuests() {
for (Guest guest : guests) {
System.out.println(guest);
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
HotelManagementSystem hotel = new HotelManagementSystem();
while (true) {
System.out.println("1. Add Guest");
System.out.println("2. Remove Guest");
System.out.println("3. List Guests");
System.out.println("4. Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1:
System.out.print("Enter guest name: ");
String name = scanner.nextLine();
System.out.print("Enter guest age: ");
int age = scanner.nextInt();
scanner.nextLine();
System.out.print("Enter guest gender: ");
String gender = scanner.nextLine();
System.out.print("Enter guest face image: ");
String faceImage = scanner.nextLine();
hotel.addGuest(new Guest(name, age, gender, faceImage));
break;
case 2:
System.out.print("Enter guest name: ");
String removeName = scanner.nextLine();
for (Guest guest : hotel.guests) {
if (guest.getName().equals(removeName)) {
hotel.removeGuest(guest);
System.out.println(removeName + " removed.");
break;
}
}
break;
case 3:
hotel.listGuests();
break;
case 4:
System.exit(0);
default:
System.out.println("Invalid choice.");
}
}
}
}
class Guest {
private String name;
private int age;
private String gender;
private String faceImage;
public Guest(String name, int age, String gender, String faceImage) {
this.name = name;
this.age = age;
this.gender = gender;
this.faceImage = faceImage;
}
public String getName() {
return name;
}
@Override
public String toString() {
return "Guest{" +
"name='" + name + '\'' +
", age=" + age +
", gender='" + gender + '\'' +
", faceImage='" + faceImage + '\'' +
'}';
}
}
```
该代码中,Guest类表示一个酒店客人,包括姓名、年龄、性别和人脸图像等属性。HotelManagementSystem类表示酒店管理系统,包括添加客人、删除客人和列出客人等操作。在添加客人时,需要输入客人的信息,包括姓名、年龄、性别和人脸图像。在删除客人时,需要输入客人的姓名。在列出客人时,将打印出所有客人的信息。
然而,如何实现人脸识别功能,则需要使用到一些第三方的人脸识别库或API,这里不再赘述。
阅读全文