iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >Java实现简单酒店管理系统
  • 190
分享到

Java实现简单酒店管理系统

2024-04-02 19:04:59 190人浏览 八月长安

Python 官方文档:入门教程 => 点击学习

摘要

用Java编写一个简单的酒店管理系统,供大家参考,具体内容如下 为某个酒店编写程序:酒店管理系统,模拟订房、退房、打印所有房间状态等功能。 1、该系统的用户是:酒店前台。2、酒店使用

用Java编写一个简单的酒店管理系统,供大家参考,具体内容如下

为某个酒店编写程序:酒店管理系统,模拟订房、退房、打印所有房间状态等功能。

1、该系统的用户是:酒店前台。
2、酒店使用一个二维数组来模拟。“Room[][] rooms;”
3、酒店中的每一个房间应该是一个java对象:Room
4、每一个房间Room应该有:房间编号、房间类型、房间是否空闲.
5、系统应该对外提供的功能:

可以预定房间:用户输入房间编号,订房。
可以退房:用户输入房间编号,退房。
可以查看所有房间的状态:用户输入某个指令应该可以查看所有房间状态。

import org.w3c.dom.ls.LSOutput;

import java.util.Objects;
//测试
public class HotelTest {
    public static void main(String[] args) {
        Hotel h=new Hotel();
        java.util.Scanner s=new java.util.Scanner(System.in);
        System.out.println("欢迎使用酒店管理系统!请认真阅读以下功能。");
        System.out.println("功能编号:1表示打印房间列表,2表示预定房间,3表示退订房间,4表示退出系统");
        while(true){
            System.out.println("请输入功能编号:");
            int i=s.nextInt();
            if(i==1){h.pri();}
            else if(i==2){
                System.out.println("请输入要预定的房间编号:");
                h.order(s.nextInt());
            }else if(i==3){
                System.out.println("请输入要退订的房间编号:");
                h.exit(s.nextInt());
            }else if(i==4){
                System.out.println("欢迎下次使用酒店管理系统,再见!");
                return;
            }else{
                System.out.println("功能编号输入错误,请重新输入!");
            }
        }

    }
}
//酒店管理系统
public class Hotel{
    Room[][] rooms;
    public Hotel(){
        rooms=new Room[3][10];
        for (int i = 0; i < rooms.length; i++) {
            for (int j = 0; j <rooms[i].length ; j++) {
                
                rooms[i][j]=new Room();
                rooms[i][j].setNo((i+1)*100+j+1);
                rooms[i][j].setType(i==0?"单人间":(i==1?"双人间":"三人间"));
                rooms[i][j].setStatus(true);
            }
        }
    }
    public void pri(){
        for (int i = 0; i <rooms.length ; i++) {
            for (int j = 0; j <rooms[i].length ; j++) {
                System.out.print(rooms[i][j]);
            }
            System.out.println();
        }
    }
    public void order(int no){
        if(rooms[no/100-1][no%100-1].isStatus()==true) {
            rooms[no / 100 - 1][no % 100 - 1].setStatus(false);
            System.out.println(no + "号房间预订成功!");
        }else{
            System.out.println(no+"号房间已被预订,房间预订失败!");
        }
    }
    public void exit(int no){
        if(rooms[no/100-1][no%100-1].isStatus()==false) {
            rooms[no / 100 - 1][no % 100 - 1].setStatus(true);
            System.out.println(no + "号房间退订成功!");
        }else{
            System.out.println(no+"号房间已被退订,房间退订失败!");
        }
    }
}
//房间
public class Room{
    private int no;
    private String type;
    private boolean status;

    public Room() {
    }

    public Room(int no, String type, boolean status) {
        this.no = no;
        this.type = type;
        this.status = status;
    }

    public int getNo() {
        return no;
    }

    public void setNo(int no) {
        this.no = no;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Room room = (Room) o;
        return no == room.no;
    }

    @Override
    public String toString() {
        return "["+no+","+type+","+(status?"空闲":"占用")+"]";
    }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程网。

--结束END--

本文标题: Java实现简单酒店管理系统

本文链接: https://www.lsjlt.com/news/149871.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作