java如何计算所有值并比较每个对象?
我有两个班,一个是客房,另一个是客人,我需要计算一下客人在房间里预订的数量,才能找到合适的房间。例如:客人预订了5人的房间,但我们有三个房间:A1001供2人使用,A1002供6人使用,A1003供8人使用。我们计算如下:| 5-2 |=3|5-6|=1; |5-8 |=3=>;我们选择房间A1002,因为它收到的值最小
public class Room {
private String roomName;
private String roomType;
private int roomNumSeat;
private int status;
}
public class Guest {
private String guestID;
private String guestName;
private double time;
private int guestNum;
private double bonus;
private ArrayList<String> guestServices= new ArrayList<String>();
private ArrayList<String> guestRoomType= new ArrayList<String>();
private Room room;
private Services services;
}
你能给我一个解决上述问题的办法吗?我不知道如何计算所有的房间和结果。 在类Guest中,我创建方法:
public String RoomForGuest(){
return this.room.Room_Guest();
}
教室:
public String Room_Guest(Guest g) {
Math.abs(g.getGuestNum()-this.roomNumSeat);
//How can i calculate all roomNumSeat and compare the value received?
return this.roomName;
}
# 1 楼答案