const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const rooms = []; // 用於存儲客房號碼的陣列
const reservations = []; // 用於存儲已預訂客房的陣列
function displayMenu() {
console.log('歡迎來到酒店管理系統');
console.log('1. 添加客房');
console.log('2. 預訂客房');
console.log('3. 查看客房列表');
console.log('4. 退出');
}
function addRoom() {
rl.question('請輸入客房號碼: ', (roomNumber) => {
rooms.push(roomNumber); // 添加客房號碼到客房陣列
console.log(`客房 ${roomNumber} 已添加`);
displayMenu();
selectOption();
});
}
function bookRoom() {
rl.question('請輸入客房號碼以預訂: ', (roomNumber) => {
if (rooms.includes(roomNumber)) {
reservations.push(roomNumber); // 標記客房為已預訂
console.log(`客房 ${roomNumber} 已預訂`);
} else {
console.log(`客房 ${roomNumber} 不存在`);
}
displayMenu();
selectOption();
});
}
function listRooms() {
console.log('客房列表:');
for (const room of rooms) {
const status = reservations.includes(room) ? '已預訂' : '可用';
console.log(`客房號碼: ${room}, 狀態: ${status}`);
}
displayMenu();
selectOption();
}
function selectOption() {
rl.question('請選擇一個選項 (1/2/3/4): ', (option) => {
switch (option) {
case '1':
addRoom();
break;
case '2':
bookRoom();
break;
case '3':
listRooms();
break;
case '4':
console.log('感謝使用酒店管理系統,再見!');
rl.close();
break;
default:
console.log('無效選項,請重新選擇');
displayMenu();
selectOption();
break;
}
});
}
displayMenu();
selectOption();