xucucu  

酒店管理系统

一、代码

1.原始代码

项目需求

  • 程序一启动,在控制台输出以下菜单

    • 用户选择1,2,3之后再一次展示菜单,可以一直选择

    • 用户选择4则提示谢谢您的使用 程序运行结束

-----酒店管理系统----

1、查看房间信息

2、办理入住

3、办理退房

4、退出系统

请选择:

内部显示:

  • 查看房间信息

    • 在控制台将所有的房间的信息展示出来

0101:小明 0102:空 0103:空 0104:空 0105:空

0201:空 。。。。。。。。。。。

  • 办理入住

    • 请输入房间号(0102 ---> [0] [1])

    • 请输入入住人姓名

    • String name = sc.next()获取用户在控制台输入的字符串

    • 判断是否可以入住(当前是否有人了)

    • 根据判断情况给出提示(入住成功/无法入住)

  • 办理退房

    • 请输入房间号

    • 判断是否可以退房(当前是否有人了)

    • 根据判断情况给出提示(退房成功/无法办理)

package net.wanke.jc.day4;
import java.util.Scanner;
​
public class T20 {
    public static void main(String[] args) {
        int temp;
        String[][] rooms = new String[4][5];
        do {
            System.out.println("————酒店管理系统————");
            System.out.println("1、查看房间信息");
            System.out.println("2、办理入住");
            System.out.println("3、办理退房");
            System.out.println("4、退出系统");
            System.out.println("请输入:");
            Scanner sc = new Scanner(System.in);
            temp = sc.nextInt();
              switch(temp) {
                case 1:
                  //查看房间信息
                  for(int i = 0;i < rooms.length;i++) {
                      for(int j = 0;j < rooms[i].length;j++) {
                          String roomNo = "0" + (i + 1) + "0" + (j + 1);
                          System.out.print(roomNo + ":" 
                                 + (rooms[i][j] == null ? "空":(rooms[i][j])) + "  ");
                      }
                      System.out.println();
                  }
                        break;
                    
                case 2:
                  //办理入住
                       System.out.println("请输入房间号:");
                       int roomNo1 = sc.nextInt();
                       int i = roomNo1 / 100 - 1;
                       int j = roomNo1 % 10 -1;
                       if(rooms[i][j] != null) {
                          System.out.println("该房间已入住。");
                          break;
                        }
                          System.out.println("请输入姓名:");
                          String name = sc.next();
                          rooms[i][j] = name;
                        break;
                 
                case 3:
                      //办理退房
                      System.out.println("请输入您的房间号");
                      int roomNo2 = sc.nextInt();
                      int i1 = roomNo2 / 100 - 1;
                      int j1 = roomNo2 % 10 - 1;
                      if(rooms[i1][j1] != null) {
                          rooms[i1][j1] = null;
                          System.out.println("已成功办理退房");
                              break;
                          }
                          System.out.println("该房间为空房间");
                          break;
            
                case 4:
                    //返回上一级
                        System.out.println("谢谢您的使用!");
                        break;
                    
                default:
                    //保证健壮性
                        System.out.println("请输入正确的内容");
                        }
                    }while(temp != 4);
                }
}

学习心得:

1.

do{
​
        }while();

运行后再做判读,也可以使用Boolean类型的flag,作为标记。

2.

switch(){
  case 1:
    break;
  case 2:
    break;
  default:
    
}

switch作为选择的常用的方法,在匹配到的选项后,break来结束,否则将延顺运行。

3.

  Scanner sc = new Scanner(System.in);
            temp = sc.nextInt();

创建新的空间来抓取用户输入。并用temp来接收。

int类型使用sc.nextInt()

非int类型使用sc.next()

 

 

posted on   XMonday  阅读(150)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
 
点击右上角即可分享
微信分享提示