[java]代码库
package com.tutoria.managentsystem;
import java.util.Scanner;
public class HotelManager {
private static String[][] rooms;
public static void main(String[] args) {
// TODO Auto-generated method stub
rooms = new String[10][12];
String comm;// 表示用户输入的命令
for (int i = 0; i < rooms.length; i++) {
for (int j = 0; j < rooms[0].length; j++) {
rooms[i][j] = "EMPTY";
}
}
while (true) {
System.out.println("欢迎光临韦小宝旅店,请输入命令:");
Scanner sca = new Scanner(System.in);
System.gc();
comm = sca.next();
if ("search".equalsIgnoreCase(comm)) {
search();
} else if ("in".equalsIgnoreCase(comm)) {
int roomNo = sca.nextInt();
String name = sca.next();
in(roomNo, name);
} else if ("out".equalsIgnoreCase(comm)) {
int roomNo = sca.nextInt();
out(roomNo);
} else if ("exit".equalsIgnoreCase(comm)) {
System.out.println("程序退出...");
break;
} else if ("help".equalsIgnoreCase(comm)) {
System.out
.println(" in命令格式:in 房号 姓名\n out命令格式:out 房号 姓名\n search命令:查看所有房间状态 \n exit命令:退出");
} else {
System.out.println("命令输入错误,请重新输入:");
}
}
}
private static void out(int roomNo) {
// TODO Auto-generated method stub
if ("EMPTY".equals(rooms[(roomNo / 100) - 1][(roomNo % 100) - 1])) {
System.out.println("该房间没有客人入住,退房失败!");
return;
}
rooms[(roomNo / 100) - 1][(roomNo % 100) - 1] = "EMPTY";
System.out.println(roomNo + "退房成功!");
}
private static void in(int roomNo, String name) {
// TODO Auto-generated method stub
if (!"EMPTY".equals(rooms[(roomNo / 100) - 1][(roomNo % 100) - 1])) {
System.out.println("该房间已经有客人入住!");
return;
}
rooms[(roomNo / 100) - 1][(roomNo % 100) - 1] = name;
System.out.println(name + "成功入住" + roomNo + "房间!");
}
private static void search() {
// TODO Auto-generated method stub
for (int i = 0; i < rooms.length; i++) {
// 打印房间号
for (int j = 0; j < rooms[0].length; j++) {
if (j + 1 < 10) {
System.out.print(i + 1 + "0" + (j + 1) + " ");
} else {
System.out.print(i + 1 + "" + (j + 1) + " ");
}
}
// 打印房间状态
System.out.println();
for (int j = 0; j < rooms[0].length; j++) {
System.out.print(rooms[i][j] + " ");
}
System.out.println();
}
}
}
by: 发表于:2020-06-07 16:27:23 顶(1) | 踩(0) 回复
源码呢
回复评论