• java初学小项目-酒店客房管理系统


    最近初次接触JAVA,感觉之前学的C语言很有用,跟着视频做了一个小项目-酒店客房管理系统

      1 /*
      2 酒店客房管理系统
      3 */
      4 import java.util.Scanner;//通过键盘来输入命令需要的引入
      5 
      6 class HotelManangerSystem
      7 {
      8     public static void main(String[] args)
      9     {
     10         //酒店有12个楼层,每层有10个房间
     11         //字符串数组如果没有被初始化,每个元素都是null
     12         String[][] rooms = new String[12][10];
     13         System.out.println("欢迎来到蒋氏集团大酒店");//换行打印
     14         System.out.println("请输入要操作的命令:search查询,in办理入住,out退房"
     15                            + "init初始化所有房间");
     16         Scanner s = new Scanner(System.in);//这个在主函数定义的,其他函数用不了
     17         
     18         while(true)
     19         {
     20             String command = s.next();//提示输入命令
     21             //比较字符串相同--"输入的字符串".equals(command)
     22             if("init".equals(command))
     23             {
     24                 init(rooms);
     25                 System.out.println("房间初始化完毕");
     26             }
     27             else if("search".equals(command))
     28             {
     29                 search(rooms);
     30             }
     31             else if("in".equals(command))
     32             {
     33                 in(rooms);
     34             }
     35             else if("out".equals(command))
     36             {
     37                 out(rooms);
     38             }
     39         }
     40         
     41         
     42     }
     43     //初始化所有的房间号
     44     public static void init(String[][] rooms)
     45     {
     46         for(int i = 0; i < 12; i++)
     47         {
     48             for(int j = 0; j < 10;j++)
     49             {
     50                 rooms[i][j] = "EMPLY";
     51             }
     52         }
     53     }
     54     public static void search(String[][] rooms)
     55     {
     56         for(int i = 0; i < rooms.length; i++)
     57         {
     58             for(int j = 0; j < rooms[i].length;j++)
     59             {
     60                 if(i < 9)
     61                 {
     62                     System.out.print("0");
     63                 }
     64                 int roomNum = (i + 1) * 100 + j + 1;
     65                 System.out.print(roomNum + "	");
     66             }
     67             System.out.println();
     68             for(int k = 0; k < rooms[i].length; k++)
     69             {
     70                 System.out.print(rooms[i][k] + "	");
     71             }
     72             System.out.println();
     73         }
     74     }
     75     public static void in(String[][] rooms)
     76     {
     77         System.out.println("请输入房间号:");
     78         Scanner s = new Scanner(System.in);
     79         int roomNum = s.nextInt();
     80                 int i = roomNum / 100;
     81         int j = roomNum % 100;
     82         if(i < 1 || i > 10 || j < 1|| j > 12)
     83         {
     84             System.out.println("输入错误,请重新输入in:");
     85             return;
     86         }
     87         if(rooms[i-1][j-1] != "EMPLY")
     88         {
     89             System.out.println("此房间已经有人入住,请重新输入in:");
     90             return;
     91         }
     92         System.out.println("请输入您的姓名:");
     93         String name = s.next();
     94         rooms[i-1][j-1] = name;    
     95         System.out.println("入住成功");        
     96     }
     97     public static void out(String[][] rooms)
     98     {
     99         System.out.println("请输入房间号:");
    100         Scanner s = new Scanner(System.in);
    101         int roomNum = s.nextInt();
    102                 int i = roomNum / 100;
    103         int j = roomNum % 100;
    104         if(i < 1 || i > 10 || j < 1|| j > 12)
    105         {
    106             System.out.println("输入错误,请重新输入out:");
    107             return;
    108         }
    109         if(rooms[i-1][j-1] == "EMPLY")
    110         {
    111             System.out.println("输入错误,请重新输入out:");
    112             return;
    113         }
    114         if(rooms[i-1][j-1] != "EMPLY")
    115         {
    116             rooms[i-1][j-1] = "EMPLY";
    117             System.out.println("退房成功");
    118         }
    119         
    120     }
    121 }
  • 相关阅读:
    手工去除 dll 和 exe 文件的数字签名
    针式PKM中级应用:文件的5S(归档整理删除)
    针式PKM初级应用:如何避免收集重复的资料?
    了解更多:什么是个人知识管理?
    如何选用知识管理软件?
    与阿朱聊个人知识管理:体系和方法论层面
    针式PKM初级应用:针式PKM每天应使用多少小时?
    战略人生
    针式PKM初级应用:针式PKM更适合管理什么样的文件
    Data, Information, and Knowledge Management Software "What software should I use?"
  • 原文地址:https://www.cnblogs.com/jiangtongxue/p/11858335.html
Copyright © 2020-2023  润新知