JavaSE實戰(zhàn)之酒店訂房系統(tǒng)的實現(xiàn)
酒店管理系統(tǒng)
為某個酒店編寫程序:酒店管理系統(tǒng),模擬訂房,退房,打印所有房間狀態(tài)等功能
1、該系統(tǒng)的用戶是酒店的前臺
2、酒店當(dāng)中所有的房間使用一個二維數(shù)組來模擬
3、酒店當(dāng)中的每一個房間應(yīng)該是一個java對象:Room
4、每一個房間Room應(yīng)該有:房間編號,房間類型屬性,房間是否空閑

Hotel.java
/**
* Created with IntelliJ IDEA.
* Description:酒店
* User: Lenovo
* Date: 2022-07-02
* Time: 20:10
*/
public class Hotel {
/**
* 二維數(shù)組,模擬大廈所有的房間
* @param args
*/
private Room[][] rooms;
public Hotel(){
//通過構(gòu)造方法來蓋樓層
rooms=new Room[3][10];//動態(tài)初始化,里面每個元素都還是null
//創(chuàng)建30個room對象,放到數(shù)組當(dāng)中
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);
}else if(i==1){
rooms[i][j]=new Room((i+1)*100+(j+1),"雙人間",true);
}else{
rooms[i][j]=new Room((i+1)*100+(j+1),"總統(tǒng)套房",true);
}
}
}
}
public void print(){
for(int i=0;i<rooms.length;i++){
for(int j=0;j<rooms.length;j++){
Room room=rooms[i][j];
System.out.println(room);
}
}
}
/**
* 訂房方法
* @param roomNo 調(diào)用此方法需要傳遞一個房間編號過來
* 這個房間編號是前臺小姐姐輸入的
*/
public void order(int roomNo){
//訂房主要是將房間對象的status修改為false
Room room=rooms[roomNo/100-1][roomNo%100-1];
//把房間狀態(tài)修改為占用
room.setStatus(false);
System.out.println(roomNo+"訂房成功!");
}
/**
* 退房
* @param roomNo
*/
public void exit(int roomNo){
Room room=rooms[roomNo/100-1][roomNo%100-1];
room.setStatus(true);
System.out.println(roomNo+"已經(jīng)退房!");
}
}
HotelSystem.java
/**
* Created with IntelliJ IDEA.
* Description:
* User: Lenovo
* Date: 2022-07-03
* Time: 18:01
*/
public class HotelSystem {
public static void main(String[] args) {
System.out.println("歡迎使用酒店管理系統(tǒng),請認(rèn)真閱讀以下說明:");
System.out.println("請輸入對應(yīng)的功能編號:【1】查看房間列表?!?】訂房?!?】退房。【0】退出系統(tǒng)");
Scanner s=new Scanner(System.in);
Hotel hotel=new Hotel();
while(true){
System.out.print("請輸入功能編號:");
int i=s.nextInt();
if(i==1){
//查看房間列表
hotel.print();
}else if(i==2){
//訂房
System.out.print("請輸入要訂房的房間號碼:");
int numNo=s.nextInt();
hotel.order(numNo);
}else if(i==3){
//退房
System.out.print("請輸入要退房的房間號碼:");
int numNo=s.nextInt();
hotel.exit(numNo);
}else if(i==0){
//退出系統(tǒng)
System.out.print("已退出系統(tǒng)");
return;
}else {
System.out.print("輸入錯誤,請重新輸入:");
}
}
}
}
Room.java
/**
* Created with IntelliJ IDEA.
* Description:酒店的房間
* User: Lenovo
* Date: 2022-07-02
* Time: 20:48
*/
import java.util.Objects;
import java.util.Scanner;
/**
* 酒店的房間
*/
public class Room {
/**
* 房間編號:int no
* 1樓:101 102 103...
* 2樓:201 202 203...
* 3樓:301 302 303...
* ...
*/
private int no;
/**
* 房間類型:標(biāo)準(zhǔn)間,單人間,總統(tǒng)套房
* String type
*/
private String type;
/**
* 房間狀態(tài)
* true:表示空閑,房間可以被預(yù)定
* false:表示占用,房間不能被預(yù)定
* boolean status
*/
private boolean status;
//構(gòu)造方法
public Room(int no, String type, boolean status) {
this.no = no;
this.type = type;
this.status = status;
}
public Room() {
}
//set和get方法
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;
}
//equals方法重寫
@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 && status == room.status && Objects.equals(type, room.type);
}
@Override
public int hashCode() {
return Objects.hash(no, type, status);
}
//toString方法重寫
@Override
public String toString() {
return "[" + "房間編號:" + no + ", 房間類型:'" + type + ", 房間狀態(tài):" + status + ']';
}
}

以上就是JavaSE實戰(zhàn)之酒店訂房系統(tǒng)的實現(xiàn)的詳細內(nèi)容,更多關(guān)于JavaSE 酒店訂房系統(tǒng)的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
java.sql.SQLException:com.mysql.cj.jdbc.Driver報錯問題解決
這篇文章主要給大家介紹了關(guān)于java.sql.SQLException:com.mysql.cj.jdbc.Driver報錯問題解決的相關(guān)資料,文中通過圖文介紹的非常詳細,需要的朋友可以參考下2023-08-08
ThreadPoolExecutor中的submit()方法詳細講解
在使用線程池的時候,發(fā)現(xiàn)除了execute()方法可以執(zhí)行任務(wù)外,還發(fā)現(xiàn)有一個方法submit()可以執(zhí)行任務(wù),本文就詳細的介紹一下ThreadPoolExecutor中的submit()方法,具有一定的參考價值,感興趣的可以了解一下2022-04-04
基于@JsonSerialize和@JsonInclude注解使用方法
這篇文章主要介紹了@JsonSerialize和@JsonInclude注解使用方法,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-10-10
Spring Boot中數(shù)據(jù)庫操作Druid和HikariDataSource的詳細過程
這篇文章主要介紹了Spring Boot中數(shù)據(jù)庫操作Druid和HikariDataSource的詳細過程,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-06-06
windows如何使用bat腳本后臺啟動/停止和重啟jar包服務(wù)
這篇文章主要介紹了windows使用bat腳本后臺啟動/停止和重啟jar包服務(wù)的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11
多線程計數(shù),怎么保持計數(shù)準(zhǔn)確的方法
這篇文章主要介紹了多線程計數(shù)的方法,有需要的朋友可以參考一下2014-01-01

