本文實例為大家分享了java實現酒店管理系統的具體代碼,供大家參考,具體內容如下
要求:
【酒店管理系統】HotelSystem.java
某酒店有12層樓,每層樓有10個房間(二維數組),要求為該酒店設計一套簡單的前臺房間管理程序,
該程序可以通過在命令行輸入命令來為客人辦理入住和退房手續。
要求該程序支持通過命令行輸入以下命令來進行入住,退房及查詢的操作:
(1)、search:查詢所有房間的狀態 無人住顯示empty,有人則顯示住戶姓名
(2)、in 房間號碼 姓名 :客人入住 命令:in 請輸入客人入住的房間號 1202 請輸入入住1202房間的顧客的姓
名 parker 提示:姓名為parker的客人入住1202房間
注意:如果某個房間已經有客人入住,在辦理入住時,將提示“該房間已有客人入住”
(3)、out 房間號碼:客人退房 命令:out 1202 提示:1202房間退房
(4)、quit:退出程序
實現:
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
131
132
133
134
135
136
137
138
|
import java.util.Scanner; public class HotelSystem { //房間數量 int [][] house= new int [ 12 ][ 10 ]; //住戶姓名 String[] householdName= new String[ 120 ]; public HotelSystem() { Init(); } //初始化數組 public void Init() { for ( int i= 0 ;i< 12 ;i++) { for ( int j= 0 ;j< 10 ;j++) { house[i][j]= 0 ; } } } //查詢 public void Search(HotelSystem hotel) { System.out.println( "■■■■■■■■■■■■房間狀態查詢結果如下■■■■■■■■■■■■" ); for ( int i= 0 ;i< 12 ;i++) { for ( int j= 0 ;j< 10 ;j++) { if (hotel.house[i][j]== 0 ) { System.out.println(i* 10 +j+ 1 + "號房間無人居住" ); } else if (hotel.house[i][j]== 1 ) { System.out.println(i* 10 +j+ 1 + "號房間" +hotel.householdName[i* 10 +j+ 1 ]+ "在住" ); } } } } //入住 public void InHouse(HotelSystem hotel, int housNums,String name,Scanner sc) { System.out.println( "■■■■■■■■■■■■客人入住■■■■■■■■■■■■" ); System.out.println( "請輸入客人入住的房間號" ); housNums=sc.nextInt(); System.out.println( "請輸入入住" +housNums+ "房間的顧客的姓名" ); name=sc.next(); for ( int i= 0 ;i< 12 ;i++) { for ( int j= 0 ;j< 10 ;j++) { if (housNums==(i* 10 +j+ 1 ) && hotel.house[i][j]== 0 ) { hotel.house[i][j]= 1 ; hotel.householdName[housNums]=name; System.out.println( "姓名為" +hotel.householdName[housNums] + "的客人入住" +housNums+ "號房間" ); return ; } else if (housNums==(i* 10 +j+ 1 ) && hotel.house[i][j]== 1 ) { System.out.println( "不好意思該房間已有客人入住" ); return ; } } } } //退房 public void OutHouse(HotelSystem hotel, int housNums,Scanner sc) { System.out.println( "■■■■■■■■■■■■客人退房■■■■■■■■■■■■" ); System.out.println( "請輸入需要退房的房間號" ); housNums=sc.nextInt(); for ( int i= 0 ;i< 12 ;i++) { for ( int j= 0 ;j< 10 ;j++) { if (housNums==(i* 10 +j+ 1 ) && hotel.house[i][j]== 1 ) { hotel.house[i][j]= 0 ; System.out.println(housNums+ "號房間成功退房" ); return ; } } } System.out.println( "退房失敗!" ); } //退出 public void Quit() { System.out.println( "■■■■■■■■■■■■退出程序■■■■■■■■■■■■" ); System.out.println( "■■■■■■■■■■■■感謝使用,系統正在退出...■■■■■■■■■■■■" ); } public static void main(String[] args) { HotelSystem hotel= new HotelSystem(); String command= null ; int housNums= 0 ; String name= null ; Scanner sc= new Scanner(System.in); while ( true ) { System.out.println( "■■■■■■■■■■■酒店管理系統命令■■■■■■■■■■■■■" ); System.out.println( "■■■■■■■■■■■1、search ■■■■■■■■■■■■■" ); System.out.println( "■■■■■■■■■■■2、in ■■■■■■■■■■■■■" ); System.out.println( "■■■■■■■■■■■3、out ■■■■■■■■■■■■■" ); System.out.println( "■■■■■■■■■■■4、quit ■■■■■■■■■■■■■" ); System.out.println( "請輸入你需要執行的命令" ); command=sc.next(); if (command.equals( "search" )) { hotel.Search(hotel); } else if (command.equals( "in" )) { hotel.InHouse(hotel, housNums, name, sc); } else if (command.equals( "out" )) { hotel.OutHouse(hotel, housNums, sc); } else if (command.equals( "quit" )) { hotel.Quit(); return ; } } } } |
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://blog.csdn.net/weixin_44350205/article/details/107600002