JAVA客房管理系统小案例^_^

JAVA客房管理系统小案例
对酒店房间进行管理,实现入住,退房,查看房间状态等功能。

import java.util.Scanner;

public class HotelManager {
    public static void main(String[] args) {
        Room[][] rooms = new Room[2][3];

        for(int i =0;i<rooms.length;i++)
        {
            for(int j=0;j<rooms[i].length;j++)
            {
                if(i>0)
                {
                    Room a = new Room(101+i*10+j,"双人房",true);
                    rooms[i][j] = a;
                }
                else {
                    Room a = new Room(101 + i * 10 + j, "单人房", true);
                    rooms[i][j] = a;
                }
            }
        }

        String input;
        do {
            System.out.print("按下 1,预订房间");
            System.out.println("\t" + "2、退房");
            System.out.print("\t" + "3、查看所有房间");
            System.out.print("\t" + "0、exit");
            System.out.println();
            Scanner scan = new Scanner(System.in);
            input = scan.nextLine();
            switch (input)
            {
                case "1" : System.out.print("请输入要预订房间号:>");
                float reserve =  scan.nextInt();
                    boolean yes = false;
                    for(int i =0;i<rooms.length;i++)
                    {

                        for(int j=0;j<rooms[i].length;j++) {

                            if(rooms[i][j].name ==reserve)
                            {
                                if(rooms[i][j].isIdle)
                                {rooms[i][j].isIdle = false;
                                System.out.println("预定成功");
yes = true;
                                break;}
                                else
                                {
                                    System.out.println("房间有人");
                                    yes=true;
                                   break;
                                }
                            }
                            else if(rooms[i][j].name ==113.0)
                            {
                                if(!yes)
                                System.out.println("输入有误!请重试");
                                break;
                            }
                        }
                    }


                    break;

                case "2":
                    System.out.print("请输入要退的房间号");
                    float checkOut = scan.nextInt();
boolean champion=false;
                    for(int i =0;i<rooms.length;i++)
                    {

                        for(int j=0;j<rooms[i].length;j++) {
                            if(rooms[i][j].name ==checkOut)
                            {
                                if(rooms[i][j].isIdle )
                                {
                                    System.out.println(rooms[i][j].name+"房未有人入住,请重试!");
                                    champion = true;
            break;
                                }
                                else
                                {
                                    rooms[i][j].isIdle =true;
                                    System.out.println("退房成功!");
                                    champion = true;
                                        break;
                                }
                            }
                            else if(rooms[i][j].name ==113.0)
                            {
                                if(!champion)
                                {
                                    System.out.println("输入有误,请重试!");
                                }
                            }
                        }
                    }
break;
                            case "3" :
                    System.out.println("房间号"+"\t"+"房间类型"+"\t"+"状态");
                    for(int i =0;i<rooms.length;i++)
                    {
                        for(int j=0;j<rooms[i].length;j++)
                        {


                            System.out.println( rooms[i][j].name+rooms[i][j].type+rooms[i][j].isIdle);
                        }
                        System.out.println();
                    }
break;
                    default:System.out.println("输入有误,请重试!");
            }
        }while("0".equals(input)==false);


       // System.out.println(rooms[1][2].type);
    }
}

//每个房间都有房间号、房间类型、状态三个属性,及有参无参两构造函数
class Room
{
    int name;
    String type;
    boolean isIdle;
    public Room(int a,String b,boolean c)
    {
        this.name =a;
        this.type = b;
        this.isIdle = c;
    }
    public Room()
    {
        this.name =0;
        this.type = "";
        this.isIdle = true;
    }
}
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值