简单的酒店订房系统

简单的酒店订房系统

 

一个不能算作项目的项目,就是一个简单的酒店的订房系统,周日会看原来的内容突然觉得这个很不错,就整理了一下。

    酒店订房系统其实总体的来看就是分为三个大部分,一个就是客户端,一个酒店的规模(就是酒店的有几层,多少房间),还有一个就是房间的的类型:
      酒店
            酒店规模
            几层
            每层几个房间
           对外提供一个酒店房间列表打印方法
           预订房间方法

实现的代码是

 

 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 +"" , "标准间",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()方法

实现的代码为

 

 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 }

 

 


       测试逻辑程序(客户端)
           实例化一个旅馆类
           实例化房间类
           调用旅馆房间列表
           预订房间方法

实现代码为

 

 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( "欢迎使用阿童木与小丸子酒店管理系统,酒店房间列表" );
 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 }

 

这样我们的整个系统就做好了,来看一下成果:

我输入一个房间号,来看一下结果

         410这个房间就会成为

一个简单的酒店的订房系统就完成了!

欢迎观看阿童木与小丸子博客

  在杰我教育学习一个多月了!还在努力!

 

 

 

posted @ 2015-09-06 19:53  ~铁臂阿童木~  阅读(630)  评论(0编辑  收藏  举报