import java.util.Scanner;

public class HelloWorld {
	public static void main(String[] args){

		String [][] room = new String[12][10];
		System.out.println("欢迎来到本酒店");
		System.out.println("请输入要操作的命令:" +
						   "serach:查询房间的状态"
							+"in:办理入住"+
						    "out:办理退房"+
							"quit:退出本系统");
		Scanner s = new Scanner(System.in);
		//比较字符串相同---->"in. equals(command)"
		while(true)
		{
			String command = s.next() ;
			if("init".equals(command)){
				init(room);
			}else if("serach".equals(command)){
				search(room);
			}else if("quit".equals(command)){
				System.out.println("欢迎再次光临本酒店!");
				break ;
			}else if("in".equals(command)){
				in(room);
			}else if("out".equals(command)){
				out(room);
			}else{
				System.out.println("输入有误,请重新输入:");
			}

		}
	}
	//输入房间号,直接退房---->需要判断房间是否存在,是否有入住
	public static void out(String[][]rooms){
		System.out.println("请输入房间:");
		Scanner s = new Scanner(System.in);
		int roomNo = s.nextInt();
		//需要把房间号转换层楼层和房间--->使其和数组的下标去对应
		int floor = roomNo / 100 ; //--->根据房间号得到楼层
		//房间号
		int no = roomNo % 100 ; //得到楼层的房间号
		if(floor < 1 || floor > 12 || no < 1 || no > 10){ //入住函数结束
			System.out.println("输入的房间号有误,请输入out命令继续操作:");
			return ;
		}
		if("EMPTY".equals(rooms[floor-1][no-1])){
			System.out.println("该房间没人入住,不需要退房,请输入out命令继续操作:");
			return ;
		}
		rooms[floor-1][no-1] = "EMPTY";
		System.out.println("该房间退房成功");
	}
	public static void search(String[][] rooms)
	{
		//打印房间号
		for(int i = 0 ; i < rooms.length ; i++)
		{
			for(int j = 0 ; j < rooms[i].length ; j++)
			{
				if(i <= 9 ){
					System.out.print("0");
				}
				int roomNo = (i+1)*100 + j+1 ;
				System.out.print(roomNo + "\t");
			}
			System.out.println();
			//打印房间的状态
			for(int k = 0 ; k < rooms[i].length ; k++)
			{
				System.out.print(rooms[i][k] + "\t");
			}
			System.out.println();
		}
	}
	//可拓展,可以先列出可入住的房间,在让用户输入房间号
	public static void in(String[][] rooms)
	{
		System.out.println("图示的房间代号为:EMPTY的为可入住房间");
		//打印现有的房间信息
		search(rooms);
		System.out.println();
		System.out.println("请输入房间号:");
		Scanner s = new Scanner(System.in);
		int roomNo = s.nextInt();
		//需要把房间号转换层楼层和房间--->使其和数组的下标去对应
		int floor = roomNo / 100 ; //--->根据房间号得到楼层
		//房间号
		int no = roomNo % 100 ; //得到楼层的房间号
		if(floor < 1 || floor > 12 || no < 1 || no > 10){ //入住函数结束
			System.out.println("输入的房间号有误,请输入in命令继续操作:");
			return ;
		}
		//判断房间是否有人入住
		if("EMPTY".equals(rooms[floor-1][no-1])){
			System.out.println("请输入您的姓名:");
			String name = s.next();
			rooms[floor-1][no-1] = name ; //对数组进行赋值操作
			System.out.println("恭喜您,入住成功!");

		}else
		{
			System.out.println(roomNo+"已经有人入住,请输入in命令继续操作:");
			return ;
		}

	}
	public static void init(String[][] rooms)
	{
		for(int i = 0 ; i < rooms.length ; i++)
		{
			for(int j = 0 ; j < rooms[i].length ; j++)
			{
				rooms[i][j] = "EMPTY";
			}
		}
		System.out.println("房间初始化完毕");
	}
}

最新文章

  1. Android 获取版本号
  2. javascript 日常总结
  3. 【PRML读书笔记-Chapter1-Introduction】1.1 Example:Polynomial Curve Fitting
  4. 2014 Super Training #2 C Robotruck --单调队列优化DP
  5. eclipse提交subversion+apache的中文路径问题解决过程
  6. [你必须知道的.NET]第三十四回,object成员,不见了!
  7. Android 文件上传 使用AsyncHttpClient开源框架
  8. MemCachedClient数据写入的三个方法
  9. ZED 相机 &amp;&amp; ORB-SLAM2安装环境配置与ROS下的调试
  10. 18-TypeScript模板方法模式
  11. Django 使用 locals() 函数
  12. modbus tcp数据报文结构
  13. 用python代码模拟登录网站
  14. ajax入门基础
  15. thymeleaf 简易使用范例
  16. rt-thread 低优先级线程挂起高优先级线程失败
  17. Bandicam录制视频
  18. PageRank算法和谷歌搜索讲解
  19. Jmeter(十六)_beanshell实现字符串加密
  20. [CISCO] 思科交换机基本配置

热门文章

  1. C语言程序设计第四次作业-选择结构
  2. 【SpringMVC】&lt;context:include-filter&gt;和&lt;context:exclude-filter&gt;使用时要注意的地方
  3. Linux下安装 mysql 5.7
  4. vue-cli搭建项目的目录结构及说明
  5. windows资源管理器中配置右键bash here
  6. webpack4.1.1的使用详细教程
  7. JavaScript switch 语句
  8. Querying CRM data with LINQ
  9. hadoop入门级总结一:HDFS
  10. Programming In Scala笔记-第十九章、类型参数,协变逆变,上界下界