[Java] 旅店管理系统(控制台版) →→→→→进入此内容的聊天室

来自 , 2020-10-03, 写在 Java, 查看 166 次.
URL http://www.code666.cn/view/e2230b85
  1. import java.util.Scanner;
  2.  
  3. /**
  4.  * 旅店管理系统(控制台版)
  5.  *
  6.  */
  7. public class HotelManager {
  8.         private static String[][] rooms;// 表示房间
  9.  
  10.         public static void main(String[] args) {
  11.                 rooms = new String[10][12];
  12.                 String comm;// 表示用户输入的命令
  13.                 for (int i = 0; i < rooms.length; i++) {
  14.                         for (int j = 0; j < rooms[0].length; j++) {
  15.                                 rooms[i][j] = "EMPTY";
  16.                         }
  17.                 }
  18.  
  19.                 while (true) {
  20.                         System.out.println("欢迎光临【程序猿】旅店,请输入命令:");
  21.                         Scanner sca = new Scanner(System.in);
  22.                         System.gc();
  23.                         comm = sca.next();
  24.                         if ("search".equalsIgnoreCase(comm)) {
  25.                                 search();
  26.                         } else if ("in".equalsIgnoreCase(comm)) {
  27.                                 int roomNo = sca.nextInt();
  28.                                 String name = sca.next();
  29.                                 in(roomNo, name);
  30.                         } else if ("out".equalsIgnoreCase(comm)) {
  31.                                 int roomNo = sca.nextInt();
  32.                                 out(roomNo);
  33.                         } else if ("exit".equalsIgnoreCase(comm)) {
  34.                                 System.out.println("程序退出...");
  35.                                 break;
  36.  
  37.                         } else if ("help".equalsIgnoreCase(comm)) {
  38.                                 System.out
  39.                                                 .println(" in命令格式:in 房号 姓名\n out命令格式:out 房号 姓名\n search命令:查看所有房间状态 \n exit命令:退出");
  40.                         } else {
  41.                                 System.out.println("命令输入错误,请重新输入:");
  42.                         }
  43.  
  44.                 }
  45.  
  46.         }
  47.  
  48.         private static void out(int roomNo) {
  49.                 if ("EMPTY".equals(rooms[(roomNo / 100) - 1][(roomNo % 100) - 1])) {
  50.                         System.out.println("该房间没有客人入住,退房失败!");
  51.                         return;
  52.                 }
  53.                 rooms[(roomNo / 100) - 1][(roomNo % 100) - 1] = "EMPTY";
  54.                 System.out.println(roomNo + "退房成功!");
  55.  
  56.         }
  57.  
  58.         private static void in(int roomNo, String name) {
  59.                 if (!"EMPTY".equals(rooms[(roomNo / 100) - 1][(roomNo % 100) - 1])) {
  60.                         System.out.println("该房间已经有客人入住!");
  61.                         return;
  62.                 }
  63.                 rooms[(roomNo / 100) - 1][(roomNo % 100) - 1] = name;
  64.                 System.out.println(name + "成功入住" + roomNo + "房间!");
  65.  
  66.         }
  67.  
  68.         private static void search() {
  69.                 for (int i = 0; i < rooms.length; i++) {
  70.                         // 打印房间号
  71.                         for (int j = 0; j < rooms[0].length; j++) {
  72.                                 if (j + 1 < 10) {
  73.                                         System.out.print(i + 1 + "0" + (j + 1) + "      ");
  74.                                 } else {
  75.                                         System.out.print(i + 1 + "" + (j + 1) + "       ");
  76.                                 }
  77.                         }
  78.                         // 打印房间状态
  79.                         System.out.println();
  80.                         for (int j = 0; j < rooms[0].length; j++) {
  81.                                 System.out.print(rooms[i][j] + "        ");
  82.                         }
  83.                         System.out.println();
  84.                 }
  85.  
  86.         }
  87.  
  88. }
  89.  

回复 "旅店管理系统(控制台版)"

这儿你可以回复上面这条便签

captcha