Hotel management system java implementation

Now provide the following requirements, please write a hotel management system, the system can check the information of the room, and can book and unsubscribe the room.
Design idea:
hotel management system;
1. Create a hotel management system
2. Create a room object, which contains room attributes, eg room number, room status, room type
3. Create a hotel, the number of rooms in this hotel is determined by yourself , Create a room generation method in the hotel class, generate a room,
create a method to print each room information, and realize the room reservation and cancellation functions
4. Optimization of the hotel management system.
We divide it into three classes for implementation: the first class is the room class, which mainly defines the properties of the room, get, set methods and construction parameters, as well as the toString method and equals method, and the second class is the hotel class , to create a room in this class, we can use a two-dimensional array to implement, in this class also complete the functions of printing room information, unsubscribing rooms and booking rooms, the third class is the hotel management system, for The front desk staff of the hotel use it, and the design is as simple and convenient as possible.
Room class source code:
import java.util.Objects;
//The property of each room
public class Room { private int no; private int status; private String type;


public Room(int no, int status, String type) {

    this.no = no;
    this.status = status;
    this.type = type;
}

public Room() {
}

public int getNo() {
    return no;
}

public void setNo(int no) {
    this.no = no;
}

public int getStatus() {
    return status;
}

public void setStatus(int status) {
    this.status = status;
}

public String getType() {
    return type;
}

public void setType(String type) {
    this.type = type;
}

@Override
public String toString() {
    return "ROOM信息{"+no+","+type+","+(status==1?"空闲":"已满")+"}";
}

@Override
public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    Room room = (Room) o;
    return no == room.no && status == room.status && Objects.equals(type, room.type);
}

@Override
public int hashCode() {
    return Objects.hash(no, status, type);
}

}

Hotel class source code:
public class Hotel { private Room [][]rooms=new Room[5][10];//Create a two-dimensional array to store room information

/* public static void main(String[] args) {
Hotel h=new Hotel();
h.makeRooms();
h.printrooninfo();
}*/
public void makeRooms()//生成房间
{
int i=0;
for (i=0;i< rooms.length;i++)
{
int j=0;
for (j=0;j<rooms[i].length;j++)
{
if(i0)
{ rooms[i][j]=new Room((i+1)*100+j+1,1,"Standard Room"); } else if(i


1)
{ rooms[i][j]=new Room((i+1)*100+j+1,1,"Couple Suite"); } else if(i


2)
{
rooms[i][j]=new Room((i+1)*100+j+1,1,“电竞房”);
}
else if(i
3)
{ rooms[i][j]=new Room((i+1)*100+j+1,1,"Capsule Room"); } else if (i==4) { rooms[i][j ]=new Room((i+1)*100+j+1,1,"Presidential Suite"); } } }







}
public void printrooninfo()//打印酒店房间信息
{
    for (int i=0;i< rooms.length;i++)
    {
        for (int j=0;j<rooms[i].length;j++)
        {
            System.out.print(rooms[i][j]);
        }
        System.out.println();
    }
}
public void reserve(int roomno)//房间预订
{
    if( (rooms[roomno/100-1][roomno%100-1].getStatus())==0)
    {
        System.out.println("预定失败,该房间已被其他吊毛预订!");
    }
    else {
        rooms[roomno/100-1][roomno%100-1].setStatus(0);
        System.out.println("预订"+roomno+"成功!");
    }


}
public void unsub(int roomno)//房间退订
{
    if( (rooms[roomno/100-1][roomno%100-1].getStatus())==1)
    {
        System.out.println("该房间已为空,请勿重复退订");
    }
    else {
        rooms[roomno/100-1][roomno%100-1].setStatus(1);
        System.out.println("退订"+roomno+"成功!");

    }

}

}

Hotel front desk management system source code:
import java.util.Scanner;
//Hotel management system

public class HotelSystem { public static void main(String[] args) { Hotel h=new Hotel(); h.makeRooms(); System.out.println("Welcome to Hanting Hotel Management System!"); System.out .println("Press 1 to view room information"); System.out.println("Press 2 to book a room"); System.out.println("Press 3 to unbook a room"); System.out.println( "Press 0 to exit the system"); while (true) { Scanner s=new Scanner(System.in); int i=s.nextInt(); if(i












1)
{
h.printrooninfo();
}
else if(i
2)
{ System.out.println("Please enter reservation number"); Scanner r=new Scanner(System.in); h.reserve(r.nextInt()); } else if(i




3)
{ System.out.println("Please enter the unsubscribe room number"); Scanner r=new Scanner(System.in); h.unsub(r.nextInt()); } else if(i




0)
{
return;
}

    }

}

}

Test:
insert image description hereThis is the end of the hotel management system, I hope it can be used for everyone to learn and improve!

Guess you like

Origin blog.csdn.net/Kirihara_Yukiho/article/details/124152262