简单的酒店订房系统
簡單的酒店訂房系統(tǒng)
?
一個不能算作項目的項目,就是一個簡單的酒店的訂房系統(tǒng),周日會看原來的內(nèi)容突然覺得這個很不錯,就整理了一下。
??? 酒店訂房系統(tǒng)其實總體的來看就是分為三個大部分,一個就是客戶端,一個酒店的規(guī)模(就是酒店的有幾層,多少房間),還有一個就是房間的的類型:
????? 酒店
??????????? 酒店規(guī)模
??????????? 幾層
??????????? 每層幾個房間
?????????? 對外提供一個酒店房間列表打印方法
?????????? 預(yù)訂房間方法
實現(xiàn)的代碼是
?
1 public class Hotel{ 2 Room rooms[][]; 3 public Hotel(){ 4 rooms = new Room[5][10]; 5 for(int i=0; i < rooms.length; ++i){ 6 for(int j=0; j < rooms[i].length; ++j){ 7 if (i == 0 || i == 1) { 8 rooms[i][j] = new Room((i+1)*100+j+1 +"" , "單人間",false); 9 } 10 if (i == 2 || i == 3) { 11 rooms[i][j] = new Room((i+1)*100+j+1 +"" , "標(biāo)準(zhǔn)間",false); 12 } 13 if (i == 4) { 14 rooms[i][j] = new Room((i+1)*100+j+1 +"" , "套間",false); 15 } 16 } 17 } 18 } 19 public void print(){ 20 for(int i=0; i < rooms.length; ++i){ 21 for(int j=0; j < rooms[i].length; ++j){ 22 System.out.println( rooms[i][j] + " " ); 23 } 24 System.out.println( ); 25 } 26 } 27 public void order(String no){ 28 for(int i=0; i < rooms.length; ++i){ 29 for(int j=0; j < rooms[i].length; ++j){ 30 if (rooms[i][j].getNo().equals(no)) { 31 rooms[i][j].setUse(true); 32 return; 33 } 34 } 35 } 36 } 37 }?
?
?????? 房間
?????????? 房間號
?????????? 房間類型
?????????? 是否使用
?????????? 房間號操作方法
?????????? 類型操作方法
?????????? 是否使用操作方法
?????????? 覆寫toString()方法
實現(xiàn)的代碼為
?
1 public class Room{ 2 private String no; 3 private String type; 4 private boolean isUse; 5 public Room(){ 6 super(); 7 } 8 public Room(String no, String type, boolean isUse){ 9 super(); 10 this.no = no; 11 this.type = type; 12 this.isUse = isUse; 13 } 14 public String getNo(){ 15 return no; 16 } 17 public void setNo(String no){ 18 this.no = no; 19 } 20 public String getType(){ 21 return type; 22 } 23 public void setType(String type){ 24 this.type = type; 25 } 26 public boolean isUse(){ 27 return isUse; 28 } 29 public void setUse(boolean isUse){ 30 this.isUse = isUse; 31 } 32 public String toString(){ 33 return "[" + no + "," + type+","+(isUse?"占用":"空閑")+"]"; 34 } 35 }?
?
?????? 測試邏輯程序(客戶端)
?????????? 實例化一個旅館類
?????????? 實例化房間類
?????????? 調(diào)用旅館房間列表
?????????? 預(yù)訂房間方法
實現(xiàn)代碼為
?
1 import java.util.Scanner; 2 public class Client{ 3 public static void main(String[] args){ 4 Scanner s = new Scanner(System.in); 5 System.out.println( "歡迎使用阿童木與小丸子酒店管理系統(tǒng),酒店房間列表" ); 6 Hotel h = new Hotel(); 7 h.print(); 8 while (true){ 9 System.out.println( "請您輸入房間編號" ); 10 String no = s.next(); 11 h.order(no); 12 h.print(); 13 } 14 } 15 }?
這樣我們的整個系統(tǒng)就做好了,來看一下成果:
我輸入一個房間號,來看一下結(jié)果
???????? 410這個房間就會成為
一個簡單的酒店的訂房系統(tǒng)就完成了!
歡迎觀看阿童木與小丸子博客
? 在杰我教育學(xué)習(xí)一個多月了!還在努力!
?
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/atongmyuxiaowanzi/p/4786996.html
總結(jié)
- 上一篇: 医学图像与高光谱图像
- 下一篇: DVD Cloner 2021 for