用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

酒店管理系统源代码

2019-11-21 作者: java1举报

[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();

	   }


	}
	

}


网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...