Java酒店订房管理系统
生活随笔
收集整理的這篇文章主要介紹了
Java酒店订房管理系统
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
需求:?
實現(xiàn)一個簡單的酒店客房管理系統(tǒng),房間信息包含,類型、樓層,房間號,價格,入住狀態(tài),它具備5個功能,
分別為【1:查看所有房間功能;2:訂房功能;3:退房功能;4:修改價格功能;5:退出本系統(tǒng)功能】
由題目我們可分析出,房間信息有五種,因此我們可以定義五個一維數(shù)組來儲存這些房間信息,
String leixing[] = {"單人間", "雙人間", "三人間"}; int louceng[] = {1, 2, 3, 4}; int fangjianhao[] = {101, 102, 201, 202, 301, 302, 401, 402}; int[] jiage= {100, 200, 300}; boolean[] ruzhuzhuangtai = {false, false, false, false, false, false, true, true};其中房間號和樓層剛好是同類型的int數(shù)組,而且也是關(guān)聯(lián)比較密切的元素,我們不妨把他們儲存在一個二維數(shù)組中。
int arr[][] = {fjh, jg};再看功能:
1.查看所有房間,將儲存了房間信息的數(shù)組中的元素遍歷出來即可。
2.訂房,我的思路是用boolean類型的數(shù)組來儲存入住狀態(tài),當(dāng)選中房間時,數(shù)組里對應(yīng)的元素變?yōu)閠rue,意為已入住,訂房成功。
3.原理同訂房,只是將true變?yōu)閒alse。
4.修改價格,我的思路是價格應(yīng)該是跟房間類型綁定在一起的,這兩個數(shù)組的長度也相同,我們輸入想要修改的房間類型和價格,并把這兩個數(shù)組都遍歷一遍,找到價格數(shù)組里下標(biāo)相對應(yīng)的元素,將新的價格賦值給數(shù)組里的元素。
5.退出,即
System.exit(0);接下來寫代碼
import java.util.*; public class jiudian {public static void main(String[] args) {String leix[] = {"單人間", "雙人間", "三人間"};int lc[] = {1, 2, 3, 4};int fjh[] = {101, 102, 201, 202, 301, 302, 401, 402};int[] jg = {100, 200, 300};boolean[] rzzt = {false, false, false, false, false, false, true, true};int arr[][] = {fjh, jg};while (true) {//在選擇功能部分加入一個死循環(huán),這樣每次從某一功能返回時,可以繼續(xù)選擇其他功能System.out.println("請輸入數(shù)字選擇功能: 1.查看所有房間 2.訂房 3.退房 4.修改價格 5.退出");Scanner sc = new Scanner(System.in);int a = sc.nextInt();switch (a) {//通過switch語句來實現(xiàn)選擇菜單的功能case 1:cksyfj(arr, rzzt);break;case 2:df(fjh, rzzt);break;case 3:tf(rzzt, fjh);break;case 4:xgjg(leix, jg);break;case 5:tc();break;default:break;}}}public static void cksyfj(int arr[][], boolean rzzt[]) {while (true) {int count = 0;System.out.println("輸入數(shù)字選擇想要查看的樓層: 1 2 3 4");Scanner sc = new Scanner(System.in);int a = sc.nextInt();for (int i = 0; i < arr.length - 1; i++) {//將二維數(shù)組遍歷int arr1[] = arr[i];for (int j = 2 * a - 2; j < (2 * a); j++) {//因為每層樓只有兩間房而且數(shù)組的下標(biāo)是從0開始,所以我們可以總結(jié)出這樣的規(guī)律System.out.println(arr1[j]);if (!rzzt[j]) {System.out.println("可入住");} else {System.out.println("不可入住");}}}System.out.println("是否查看其他樓層? 按2繼續(xù)查看 按1停止查看");Scanner sc1 = new Scanner(System.in);int b = sc.nextInt();if (b == 1) {//通過if循環(huán)來實現(xiàn)繼續(xù)或者停止該功能進(jìn)行,切記該語句要寫在for循環(huán)之外,才能正確停止整個查看房間的循環(huán)break;} else if (b == 2) {continue;} else {System.out.println("輸入錯誤,請輸入1(停止)或者2(繼續(xù))");}}}public static boolean[] df(int fjh[], boolean rzzt[]) {while (true) {System.out.println("請輸入數(shù)字選擇房間號:");Scanner sc = new Scanner(System.in);int f = sc.nextInt();int count = 0;for (int i = 0; i < fjh.length; i++) {count++;if (f == fjh[i]) {//房間號的數(shù)組與入住狀態(tài)的數(shù)組長度一直,所以通過找到房間號的下標(biāo)來確定入住狀態(tài)數(shù)組里對應(yīng)元素的位置System.out.println("找到了");break;}else{System.out.println("請輸入正確的房間號");//要判斷輸入的房間號是否存在}}if (rzzt[count - 1]) {//判斷房間是否已經(jīng)入住System.out.println("已入住,請選擇其他房間");continue;} else {for (int j = 0; j < rzzt.length; j++) {if (count == j) {rzzt[j] = true;System.out.println("訂房成功");break;}}}System.out.println("是否繼續(xù)訂房,按2繼續(xù)訂房,按1停止");Scanner sc1 = new Scanner(System.in);int a = sc.nextInt();if (a == 1) {break;} else if (a == 2) {continue;} else {System.out.println("輸入錯誤,請輸入1(停止)或者2(繼續(xù))");}}return rzzt;}public static boolean[] tf(boolean rzzt[], int fjh[]) {while (true) {System.out.println("請輸入數(shù)字選擇房間號:");Scanner sc = new Scanner(System.in);int f = sc.nextInt();int count = 0;for (int i = 0; i < fjh.length; i++) {count++;if (f == fjh[i]) {System.out.println("找到了");break;}else{System.out.println("請輸入正確的房間號:");}}if (!rzzt[count - 1]) {System.out.println("已搬出,請選擇其他房間");continue;} else {for (int j = 0; j < rzzt.length; j++) {if (count == j) {rzzt[j] = false;System.out.println("退房成功");break;}}}System.out.println("是否繼續(xù)退房,按2繼續(xù)退房,按1停止");Scanner sc1 = new Scanner(System.in);int a = sc.nextInt();if (a == 1) {break;} else if (a == 2) {continue;} else {System.out.println("輸入錯誤,請輸入1(停止)或者2(繼續(xù))");}}return rzzt;}public static int[] xgjg(String[] leix, int jg[]) {while (true) {System.out.println("各類型房間價格為:");for (int i = 0; i < leix.length; i++) {System.out.println(leix[i] + " " + jg[i]);//打印出現(xiàn)有的房間類型和價格}System.out.println("輸入想要修改的房間類型和價格");Scanner sc = new Scanner(System.in);String lx = sc.next();int jg1 = sc.nextInt();int count = 0;for (int i = 0; i < leix.length; i++) {count++;if (lx.equals(leix[i])) {//輸入的當(dāng)房間類型匹配時,進(jìn)入下一步break;}}for (int j = 0; j < leix.length; j++) {if (count - 1 == j) {jg[j] = jg1;}}System.out.println("是否繼續(xù)修改價格,按2繼續(xù),按1停止");Scanner sc1 = new Scanner(System.in);int a = sc.nextInt();if (a == 1) {break;} else if (a == 2) {continue;} else {System.out.println("輸入錯誤,請輸入1(停止)或者2(繼續(xù))");}}return jg;}public static void tc() {System.exit(0);} }總結(jié)
以上是生活随笔為你收集整理的Java酒店订房管理系统的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ios工程超级无敌详细设置(包括home
- 下一篇: 酒店在线订房系统如何开发?