您的位置:首页 > 编程语言 > Java开发

Java项目案例:酒店前台客服管理系统

2016-08-19 17:02 435 查看
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("房间初始化完毕");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐