//------------Customer----------------
public class Customer {
private String id;
private String name;
private int relation;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getRelation() {
return relation;
}
public void setRelation(int relation) {
this.relation = relation;
}
}
//------------Room----------------
public abstract class Room {
private String roomNo;
private Customer[] customers;
public abstract boolean checkIn(Customer[] customers);
public abstract boolean checkOut();
public Room() {
}
public Room(String roomNo) {
this.roomNo = roomNo;
}
public String getRoomNo() {
return roomNo;
}
public void setRoomNo(String roomNo) {
this.roomNo = roomNo;
}
public Customer[] getCustomers() {
return customers;
}
public void setCustomers(Customer[] customers) {
this.customers = customers;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Room) {
Room other = (Room) obj;
return this.getRoomNo().equals(other.getRoomNo());
}
return false;
}
@Override
public int hashCode() {
int result = 17;
result = 31 * result + roomNo.hashCode();
return result;
}
@Override
public String toString() {
return "RoomNo:" + this.getRoomNo();
}
}
//------------SingleRoom----------------
public class SingleRoom extends Room {
public SingleRoom() {
}
public SingleRoom(String roomNo) {
super(roomNo);
}
@Override
public boolean checkIn(Customer[] customers) {
if(customers.length != 1) {
return false;
}
this.setCustomers(customers);
return true;
}
@Override
public boolean checkOut() {
return true;
}
}
//------------DoubleRoom----------------
public class DoubleRoom extends Room {
public DoubleRoom() {
super();
}
public DoubleRoom(String roomNo) {
super(roomNo);
}
@Override
public boolean checkIn(Customer[] customers) {
if(customers.length != 2 || customers[0].getRelation() != customers[1].getRelation()) {
return false;
}
this.setCustomers(customers);
return true;
}
@Override
public boolean checkOut() {
return true;
}
}
//------------Hotel----------------
import java.util.HashSet;
import java.util.Set;
public class Hotel {
private String name;
private String address;
private Set
public void InitRooms() {
rooms = new HashSet
Room s1 = new SingleRoom("S1");
rooms.add(s1);
Room s2 = new SingleRoom("S2");
rooms.add(s2);
Room s3 = new SingleRoom("S3");
rooms.add(s3);
Room d1 = new DoubleRoom("D1");
rooms.add(d1);
Room d2 = new DoubleRoom("D2");
rooms.add(d2);
}
private Room getRoom(String roomNo) {
for(Room room : rooms) {
if(room.getRoomNo().equals(roomNo)) {
return room;
}
}
return null;
}
public boolean checkRoom(String roomNo) {
Room room = getRoom(roomNo);
if(room != null && room.getCustomers() == null) {
return true;
}
return false;
}
public boolean checkIn(Customer[] customers, String roomNo) {
Room room = getRoom(roomNo);
if(room != null) {
return room.checkIn(customers);
}
return false;
}
public boolean checkOut(String roomNo) {
Room room = getRoom(roomNo);
if(room != null) {
return room.checkOut();
}
return false;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Set
return rooms;
}
public void setRooms(Set
this.rooms = rooms;
}
}
如果你读的是大学而且这是答辩题,如果你还自己写不了(或者是根本就不想写),还是快点回家去种地吧。
我有兴趣给你做一下