Java實現(xiàn)簡單酒店管理系統(tǒng)
用Java編寫一個簡單的酒店管理系統(tǒng),供大家參考,具體內(nèi)容如下
為某個酒店編寫程序:酒店管理系統(tǒng),模擬訂房、退房、打印所有房間狀態(tài)等功能。
1、該系統(tǒng)的用戶是:酒店前臺。
2、酒店使用一個二維數(shù)組來模擬。“Room[][] rooms;”
3、酒店中的每一個房間應(yīng)該是一個java對象:Room
4、每一個房間Room應(yīng)該有:房間編號、房間類型、房間是否空閑.
5、系統(tǒng)應(yīng)該對外提供的功能:
可以預(yù)定房間:用戶輸入房間編號,訂房。
可以退房:用戶輸入房間編號,退房。
可以查看所有房間的狀態(tài):用戶輸入某個指令應(yīng)該可以查看所有房間狀態(tài)。
import org.w3c.dom.ls.LSOutput; import java.util.Objects; //測試 public class HotelTest { ? ? public static void main(String[] args) { ? ? ? ? Hotel h=new Hotel(); ? ? ? ? java.util.Scanner s=new java.util.Scanner(System.in); ? ? ? ? System.out.println("歡迎使用酒店管理系統(tǒng)!請認真閱讀以下功能。"); ? ? ? ? System.out.println("功能編號:1表示打印房間列表,2表示預(yù)定房間,3表示退訂房間,4表示退出系統(tǒng)"); ? ? ? ? while(true){ ? ? ? ? ? ? System.out.println("請輸入功能編號:"); ? ? ? ? ? ? int i=s.nextInt(); ? ? ? ? ? ? if(i==1){h.pri();} ? ? ? ? ? ? else if(i==2){ ? ? ? ? ? ? ? ? System.out.println("請輸入要預(yù)定的房間編號:"); ? ? ? ? ? ? ? ? h.order(s.nextInt()); ? ? ? ? ? ? }else if(i==3){ ? ? ? ? ? ? ? ? System.out.println("請輸入要退訂的房間編號:"); ? ? ? ? ? ? ? ? h.exit(s.nextInt()); ? ? ? ? ? ? }else if(i==4){ ? ? ? ? ? ? ? ? System.out.println("歡迎下次使用酒店管理系統(tǒng),再見!"); ? ? ? ? ? ? ? ? return; ? ? ? ? ? ? }else{ ? ? ? ? ? ? ? ? System.out.println("功能編號輸入錯誤,請重新輸入!"); ? ? ? ? ? ? } ? ? ? ? } ? ? } }
//酒店管理系統(tǒng) public class Hotel{ ? ? Room[][] rooms; ? ? public Hotel(){ ? ? ? ? rooms=new Room[3][10]; ? ? ? ? for (int i = 0; i < rooms.length; i++) { ? ? ? ? ? ? for (int j = 0; j <rooms[i].length ; j++) { ? ? ? ? ? ? ? ? /*if(i==0){rooms[i][j]=new Room((i+1)*100+j+1,"單人間",true);} ? ? ? ? ? ? ? ? if(i==1){rooms[i][j]=new Room((i+1)*100+j+1,"雙人間",true);} ? ? ? ? ? ? ? ? if(i==2){rooms[i][j]=new Room((i+1)*100+j+1,"三人間",true);}*/ ? ? ? ? ? ? ? ? rooms[i][j]=new Room(); ? ? ? ? ? ? ? ? rooms[i][j].setNo((i+1)*100+j+1); ? ? ? ? ? ? ? ? rooms[i][j].setType(i==0?"單人間":(i==1?"雙人間":"三人間")); ? ? ? ? ? ? ? ? rooms[i][j].setStatus(true); ? ? ? ? ? ? } ? ? ? ? } ? ? } ? ? public void pri(){ ? ? ? ? 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 order(int no){ ? ? ? ? if(rooms[no/100-1][no%100-1].isStatus()==true) { ? ? ? ? ? ? rooms[no / 100 - 1][no % 100 - 1].setStatus(false); ? ? ? ? ? ? System.out.println(no + "號房間預(yù)訂成功!"); ? ? ? ? }else{ ? ? ? ? ? ? System.out.println(no+"號房間已被預(yù)訂,房間預(yù)訂失敗!"); ? ? ? ? } ? ? } ? ? public void exit(int no){ ? ? ? ? if(rooms[no/100-1][no%100-1].isStatus()==false) { ? ? ? ? ? ? rooms[no / 100 - 1][no % 100 - 1].setStatus(true); ? ? ? ? ? ? System.out.println(no + "號房間退訂成功!"); ? ? ? ? }else{ ? ? ? ? ? ? System.out.println(no+"號房間已被退訂,房間退訂失??!"); ? ? ? ? } ? ? } }
//房間 public class Room{ ? ? private int no; ? ? private String type; ? ? private boolean status; ? ? public Room() { ? ? } ? ? public Room(int no, String type, boolean status) { ? ? ? ? this.no = no; ? ? ? ? this.type = type; ? ? ? ? this.status = status; ? ? } ? ? public int getNo() { ? ? ? ? return no; ? ? } ? ? public void setNo(int no) { ? ? ? ? this.no = no; ? ? } ? ? public String getType() { ? ? ? ? return type; ? ? } ? ? public void setType(String type) { ? ? ? ? this.type = type; ? ? } ? ? public boolean isStatus() { ? ? ? ? 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 no == room.no; ? ? } ? ? @Override ? ? public String toString() { ? ? ? ? return "["+no+","+type+","+(status?"空閑":"占用")+"]"; ? ? } }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JDK13.0.1安裝與環(huán)境變量的配置教程圖文詳解(Win10平臺為例)
這篇文章主要介紹了JDK13.0.1安裝與環(huán)境變量的配置教程圖文詳解(Win10平臺為例),本文圖文并茂給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2020-01-01SpringBoot項目整合Log4j2實現(xiàn)自定義日志打印失效問題解決
這篇文章主要介紹了SpringBoot項目整合Log4j2實現(xiàn)自定義日志打印失效問題解決,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2024-01-01