博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java项目案例:酒店前台客服管理系统
阅读量:7115 次
发布时间:2019-06-28

本文共 2756 字,大约阅读时间需要 9 分钟。

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("房间初始化完毕");	}}

转载地址:http://owzel.baihongyu.com/

你可能感兴趣的文章
Kubelet Deivce Manager源码分析
查看>>
JAVA中的集合类Map、Set、List
查看>>
apache日志分析
查看>>
安装Apache2.4出现的问题
查看>>
便携无线路由器PW2880
查看>>
alternatives命令用法
查看>>
ASP.NET MVC 3 网站优化总结(六)压缩 HTML
查看>>
我的友情链接
查看>>
拥抱阳光下的产业--光伏新技术、新产品、新工艺发布会顺利召开
查看>>
我的友情链接
查看>>
要考虑
查看>>
文件的上传
查看>>
Oracle日常巡检维护中常用的一些STUFF
查看>>
我的友情链接
查看>>
css 实现小三角
查看>>
Nginx的配置
查看>>
手势 UIPinchGestureRecognizer 捏合手势
查看>>
vim配置
查看>>
[Swift]UIKit学习之滑块控件UISlider的用法
查看>>
我的友情链接
查看>>