• Java连载87-酒店管理系统练习、哈希表、函数


    一、创建一个酒店的房间管理系统

    需求:这个酒店有五层,并且1-2层是标准间,3-4层是双人间,5层是豪华间;我们需要实时的显现各个房间的使用状态,并且我们可以预定某一个房间。

    package com.bjpowernode.java_learning;
    
    ​
    
    import java.util.Scanner;
    
    ​
    
    public class D87_1_ {
    
      public static void main(String[] args) {
    
        Scanner s = new Scanner(System.in);
    
        Hotel87 h = new Hotel87();
    
        h.print();
    
        while (s.hasNext()) {
    
          System.out.println("请输入您要预定的房间");
    
          String number = s.next();
    
          h.order(number);
    
          h.print();
    
        }
    
      }
    
    }
    
    class Room87{
    
      private String no;
    
      private String type;//标准间、双人间、豪华间
    
      private boolean isUse;//false表示空间,true表示占用
    
      /**
    
       * @param no
    
       * @param type
    
       * @param isUse
    
       */
    
      Room87(String no, String type, boolean isUse) {
    
        super();
    
        this.no = no;
    
        this.type = type;
    
        this.isUse = isUse;
    
      }
    
      public String getNo() {
    
        return no;
    
      }
    
      public void setNo(String no) {
    
        this.no = no;
    
      }
    
      public String getType() {
    
        return type;
    
      }
    
      public void setType(String type) {
    
        this.type = type;
    
      }
    
      public boolean isUse() {
    
        return isUse;
    
      }
    
      public void setUse(boolean isUse) {
    
        this.isUse = isUse;
    
      }
    
      public String toString() {
    
        return "{" + no +"," +(isUse?"占用":"空间") + "}";
    
      }
    
    }
    
    class Hotel87 {
    
      //房间
    
      Room87[][] rooms;
    
      //Constructer
    
      Hotel87(){
    
        //五层 每层十间
    
        rooms = new Room87[5][10];
    
        //赋值
    
        //1,2标准间
    
        //3,4双人间
    
        //5 豪华间
    
        for(int i=0;i<rooms.length;i++) {
    
          for(int j=0;j<rooms[i].length;j++) {
    
            if (i==0 || i==1) {
    
              rooms[i][j] = new Room87((i+1)*100+j+"","标准间",false);
    
            }
    
            if (i==2 || i==3) {
    
              rooms[i][j] = new Room87((i+1)*100+j+"","双人间",false);
    
            }
    
            if (i==4) {
    
              rooms[i][j] = new Room87((i+1)*100+j+"","豪华间",false);
    
            }
    
    ​
    
          }
    
        }
    
      }
    
      //对外提供一个打印酒店房间列表的方法
    
      public void print() {
    
        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(String no) {
    
        for(int i=0;i<rooms.length;i++) {
    
          for(int j=0;j<rooms[i].length;j++) {
    
            if(rooms[i][j].getNo().equals(no)) {
    
              //将该房间改为占用
    
              rooms[i][j].setUse(true);
    
              return;
    
            }
    
          }
    
        }
    
      }
    
    }

    二、HashSet

    1.HashSet是set的一个实现类;

    2.HashSet底层是一个HashMap;

    3.哈希表是什么

     

    三、源码:

    D87_1_HotelManageSystem.java

    D87_2_HashSet.java

    https://github.com/ruigege66/Java/blob/master/D87_1_HotelManageSystem.java

    https://github.com/ruigege66/Java/blob/master/D87_2_HashSet.java

    2.CSDN:https://blog.csdn.net/weixin_44630050

    3.博客园:https://www.cnblogs.com/ruigege0000/

    4.欢迎关注微信公众号:傅里叶变换,个人公众号,仅用于学习交流,后台回复”礼包“,获取大数据学习资料

     

  • 相关阅读:
    Python内置函数 __import__ 动态加载模块
    Django_静态资源配置和ajax(九)
    GO语言学习(五)Go 语言基础语法
    GO语言学习(四)GO语言语言结构
    GO语言学习(三)GO语言学习API文档
    GO语言学习(二)Windows 平台下 LiteIDE 的安装和使用
    GO语言学习(一)Windows 平台下 Go 语言的安装和环境变量设置
    VS无法访问IIS元数据库 您没有足够的特权访问计算机上的IIS网站
    本地存储localStorage以及它的封装接口store.js的使用
    操作类封装
  • 原文地址:https://www.cnblogs.com/ruigege0000/p/12348311.html
Copyright © 2020-2023  润新知