java写一个订房系统

时间: 2023-08-15 17:08:52 浏览: 33
好的,下面是一个简单的Java订房系统的实现示例: ```java import java.util.Scanner; public class HotelBookingSystem { private static int[][] rooms = new int[3][10]; // 三层楼,每层10个房间 private static int[] prices = {200, 300, 400}; // 每个房间的价格,分别对应三个等级的房间 public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (true) { System.out.println("欢迎使用酒店订房系统,请输入相应的数字选择服务:"); System.out.println("1. 查看房间列表"); System.out.println("2. 预订房间"); System.out.println("3. 退订房间"); System.out.println("4. 退出系统"); int choice = scanner.nextInt(); switch (choice) { case 1: printRooms(); break; case 2: bookRoom(scanner); break; case 3: cancelRoom(scanner); break; case 4: System.out.println("感谢使用酒店订房系统,再见!"); System.exit(0); break; default: System.out.println("无效的选择,请重新输入!"); break; } } } // 输出所有房间的状态 private static void printRooms() { System.out.println("所有房间的状态如下:"); for (int i = 0; i < rooms.length; i++) { System.out.println("第" + (i + 1) + "层:"); for (int j = 0; j < rooms[i].length; j++) { System.out.print("房间" + (j + 1) + ":" + (rooms[i][j] == 0 ? "空闲" : "已预订") + "\t"); } System.out.println(); } } // 预订房间 private static void bookRoom(Scanner scanner) { System.out.println("请输入要预订的房间号(格式为:层数 房间号):"); int floor = scanner.nextInt() - 1; int roomNumber = scanner.nextInt() - 1; if (floor < 0 || floor >= rooms.length || roomNumber < 0 || roomNumber >= rooms[floor].length) { System.out.println("无效的房间号,请重新输入!"); return; } if (rooms[floor][roomNumber] == 1) { System.out.println("该房间已被预订,请重新选择房间!"); } else { System.out.println("请选择要预订的房间等级(1-经济型,2-舒适型,3-豪华型):"); int level = scanner.nextInt() - 1; if (level < 0 || level >= prices.length) { System.out.println("无效的房间等级,请重新输入!"); } else { rooms[floor][roomNumber] = 1; System.out.println("房间预订成功,房间号为:" + (floor + 1) + "-" + (roomNumber + 1) + ",房间等级为:" + (level + 1) + ",价格为:" + prices[level]); } } } // 退订房间 private static void cancelRoom(Scanner scanner) { System.out.println("请输入要退订的房间号(格式为:层数 房间号):"); int floor = scanner.nextInt() - 1; int roomNumber = scanner.nextInt() - 1; if (floor < 0 || floor >= rooms.length || roomNumber < 0 || roomNumber >= rooms[floor].length) { System.out.println("无效的房间号,请重新输入!"); return; } if (rooms[floor][roomNumber] == 0) { System.out.println("该房间未被预订,请重新选择房间!"); } else { rooms[floor][roomNumber] = 0; System.out.println("房间退订成功,房间号为:" + (floor + 1) + "-" + (roomNumber + 1)); } } } ``` 这个订房系统基于命令行界面,提供了查看房间列表、预订房间、退订房间等功能。房间列表以矩阵的形式输出,每个房间有三个等级可供选择。房间的预订和退订都需要输入房间号,层数和房间号都是从1开始计数。

相关推荐

最新推荐

recommend-type

基于java web的旅行攻略网站

3.旅游信息查询:该功能实际是在网页上插了一个百度地图容器,需要连接网络便可以查看,假如用户想知道自己的景点或者酒店在哪,就可以很方便的定位了。 4.酒店预订功能:该功能也在首页有所显示,管理员通过添加...
recommend-type

J2EE课程设计(酒店订房系统)-报告部分

代码写得很垃圾,只用了2天。但购物车,后台管理等功能都全。 数据库用MYSQL,工具是MYECLIPSE! 但是拿来做课程设计已经足以。还拿了个优。哈哈......
recommend-type

Uml面向对象分析,建模与设计实验报告

1.某酒店订房系统描述如下: (1) 顾客可以选择在线预订,也可以直接去酒店通过前台服务员预订; (2) 前台服务员可以利用系统直接在前台预订房间; 。。。 2.现有一医院病房监护系统: (1)病症监视器安置在每个...
recommend-type

数据库课程设计宾馆住宿管理系统

系统模块分析 (1)系统管理模块 该模块实现操作员的管理,如添加删除和修改操作,并设置操作员的操作权限对指定的用户进行密码修改. (2)客房管理模块状 该模块实现对客房的基本信息的设置,如客房的地点,客房等级,...
recommend-type

管理系统——宾馆管理系统

宾馆酒店住宿管理系统,具有订房,住宿,退房等功能。此为本人毕业设计,仅供参考~
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

spring添加xml配置文件

1. 创建一个新的Spring配置文件,例如"applicationContext.xml"。 2. 在文件头部添加XML命名空间和schema定义,如下所示: ``` <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。