1 room
/**
* 房间
* Created by user on 2019/4/13.
*/
public class Room {
public float area;
public float price;
public Room(float area, float price) {
this.area = area;
this.price = price;
}
}
2 中介
/**
* 中介 (中介与room是真正的朋友,中介与房间知晓)
* Created by user on 2019/4/13.
*/
public class Mediator {
List<Room> mRoom = new ArrayList<>();
public Mediator() {
for (int i = 0; i < 5; i++) {
mRoom.add(new Room(14 + i, (14 + i) * 150));
}
}
public Room rentOut(float area,float price,float diffArea,float diffPrice){
for (Room room : mRoom) {
if(isSuitable(area,price,diffArea,diffPrice,room)){
return room;
}
}
return null;
}
public boolean isSuitable(float area,float price,float diffArea,float diffPrice,Room room){
return Math.abs(room.area - area) < diffArea &&
Math.abs(room.price - price) < diffPrice;
}
}
3 租户
/**
* 租户 (租户与room之间不是真正的朋友/相互不可知,查询应在中介中)
* Created by user on 2019/4/13.
*/
public class Tenant {
public float roomArea;
public float roomPrice;
public static final float diffArea = 0.001f;
public static final float diffPrice = 100.000f;
public void rentRoom(Mediator mediator){
Room room = mediator.rentOut(roomArea, roomPrice, diffArea, diffPrice);
}
}