1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
| import java.util.Objects; import java.util.Scanner;
public class _413_酒店管理系统部分功能实现 { public static void main(String[] args) {
Hotel hotel = new Hotel(3,6);
System.out.println("欢迎使用酒店管理系统,请认真使用以下说明"); System.out.println("功能对应编号:[1]表示查看房间列表, [2]订房, [3]退房"); Scanner scanner = new Scanner(System.in); System.out.println("请输入房间编号~");
while(true){ int op = scanner.nextInt(); if(op == 1){ hotel.printRooms(); } else if(op == 2){ System.out.println("请输入房间ID"); int roomID = scanner.nextInt(); hotel.order(roomID); } else if(op == 3){ System.out.println("请输入房间ID"); int roomID = scanner.nextInt(); hotel.exit(roomID); } else{ System.out.println("输入有误~"); } }
} }
class Hotel{ private Room[][] rooms;
public Hotel(int x, int y) { rooms = new Room[x][y]; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { if(i == 0) rooms[i][j] = new Room((i+1)*100+j+1,"标准间",true); else if(i == 1) rooms[i][j] = new Room((i+1)*100+j+1,"单人间",true); else if(i == 2) rooms[i][j] = new Room((i+1)*100+j+1,"双人间",true); else if(i == 3) rooms[i][j] = new Room((i+1)*100+j+1,"三人间",true); } } }
public void printRooms(){ for (int i = 0; i < rooms.length; i++) { for (int j = 0; j < rooms[i].length; j++) { System.out.printf(rooms[i][j].toString() + " "); } System.out.println(); } }
public void order(int roomId){ rooms[roomId/100 - 1][roomId%100 - 1].setStatus(false); }
public void exit(int roomId){ rooms[roomId/100 - 1][roomId%100 - 1].setStatus(true); } }
class Room{ private int roomId; private String type; private boolean status;
public Room() { }
public Room(int roomId, String type, boolean status) { this.roomId = roomId; this.type = type; this.status = status; }
public int getRoomId() { return roomId; }
public void setRoomId(int roomId) { this.roomId = roomId; }
public String getType() { return type; }
public void setType(String type) { this.type = type; }
public boolean getStatus() { return status; }
public void setStatus(boolean status) { this.status = status; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Room room = (Room) o; return roomId == room.roomId && status == room.status && Objects.equals(type, room.type); }
@Override public String toString() { return "Room{" + "roomId=" + roomId + ", type='" + type + '\'' + ", status=" + status + '}'; } }
|