java OOD酒店管理系统[已关闭]

bxgwgixi  于 2023-01-01  发布在  Java
关注(0)|答案(1)|浏览(278)
    • 已关闭**。此问题需要超过focused。当前不接受答案。
    • 想要改进此问题吗?**更新此问题,使其仅关注editing this post的一个问题。

5小时前关门了。
Improve this question
我正在开发一个酒店管理系统,我认为我目前关于预订过程的方法是错误的。我想知道是否有人可以帮助我设计它,所以它使用了好的设计原则。我对Client类中的bookRoom()方法没有信心。
这是密码:

public class Client {
    private String name;
    private String surname;
    private List<Reservation> clientReservations;

    public Client(String name, String surname) {
        this.name = name;
        this.surname = surname;
        this.clientReservations = new ArrayList<>();
    }
    //Should Go Getters and Setters
  
    public void bookRoom(LocalDate startDate, LocalDate endDate, Room room) {
            Reservation reservation = room.addReservation(startDate, endDate, this);
            clientReservations.add(reservation);
    }

----------------------------------------------------------------------

public class Room {
    private String roomID;
    private Category category;
    private int price;
    private List<Reservation> reservations;

    public Room(String roomID, Category category, int price) {
       //Set the values
    }

  //Should Go Getters and Setters

    public Reservation addReservation(LocalDate startDate, LocalDate endDate,Client client){
        if (!isReserved(startDate,endDate)) {
            Reservation reservation = new Reservation(this, startDate, endDate, client);
            reservations.add(reservation);
            return reservation;
        }
        return null;
    }

----------------------------------------------------------------------

public class Reservation {
    private Client client;
    private Room room;

    private LocalDate startDate;

    private LocalDate endDate;

    public Reservation(Room room,LocalDate startDate,LocalDate endDate,Client client) {
        this.room = room;
        this.client = client;
        this.startDate = startDate;
        this.endDate = endDate;
    }

    public Room getRoom() {
        return room;
    }

    public Client getClientName() {
        return client;
    }

    public LocalDate getStartDate() {
        return startDate;
    }

    public LocalDate getEndDate() {
        return endDate;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Reservation that = (Reservation) o;
        return client.getName().equals(that.client.getName()) && room.getRoomID().equals(that.room.getRoomID());
    }

    @Override
    public int hashCode() {
        return Objects.hash(client, room);
    }

}

我试着应用面向对象的原则,但我仍然有点迷失的设计,它不觉得灵活。

bkkx9g8r

bkkx9g8r1#

良好的开端。您应保持客户和房间等级独立于预订。您可以在客户等级中包括可选字段,如偏好,过敏,关键日期(生日,周年纪念日列表)。您也可以添加父级酒店和房间等级成为父级酒店的子级;房间等级应包括房间的特征,例如面朝大海面朝城市

相关问题