温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

使用Java怎么编写一个酒店前台管理系统

发布时间:2021-03-02 14:54:22 来源:亿速云 阅读:229 作者:戴恩恩 栏目:开发技术

本文章向大家介绍使用Java怎么编写一个酒店前台管理系统的基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

Java可以用来干什么

Java主要应用于:1. web开发;2. Android开发;3. 客户端开发;4. 网页开发;5. 企业级应用开发;6. Java大数据开发;7.游戏开发等。

Room类(酒店房间类)

package com.kukudeyu.hotelsystem; public class Room {  private int id;  //房间编号  private String type;  //房间类型  private boolean status;  //房间状态:true表示空闲,false表示占用  public Room() {  }  public Room(int id, String type, boolean status) {  this.id = id;  this.type = type;  this.status = status;  }  public int getId() {  return id;  }  public void setId(int id) {  this.id = id;  }  public String getType() {  return type;  }  public void setType(String type) {  this.type = type;  }  public boolean getStatus() {  return status;  }  public void setStatus(boolean status) {  this.status = status;  }  /*  * 重写toString方法  * 打印出房间详情信息,其中包括房间编号,类型,状态  * */  @Override  public String toString() {  return "[" + this.id + "," + this.type + "," + (this.status ? "空闲":"占用" ) + "]";  }  // 按照惯例,重写equals方法,作用为判断两个房间是否为一个房间  @Override  public boolean equals(Object o) {  if (this == o) return true;  if (o == null || !(o instanceof Room)) return false;  Room room = (Room)o;  if(this.id == room.id){   return true;  }  return false;  } }

Hotel类(酒店类)

package com.kukudeyu.hotelsystem; public class Hotel {  private 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++) {   if (i == 0) {    rooms[i][j] = new Room((i + 1) * 100 + j + 1, "单人间", true);   } else if (i == 1) {    rooms[i][j] = new Room((i + 1) * 100 + j + 1, "双人间", true);   } else if (i == 2) {    rooms[i][j] = new Room((i + 1) * 100 + j + 1, "总统套房", true);   }   }  }  }  /*  print方法提供查看房间列表功能,可以查询所有房间的当前状态  利用循环将所有房间对象均调用Room类的toString方法进行房间状态查询  */  public void print(){  for(int i = 0 ; i< rooms.length ; i++){   for(int j = 0 ; j<rooms[i].length ; j++){   System.out.print(rooms[i][j].toString()); //调用Room类重写的toString方法,查看单个房间的状态   }   System.out.println();  }  }  /*  提供booking方法,用于修改房间状态  即订房  调用getStatus方法查询房间状态  如果为true为空闲,提示订房成功  如果为false为占用,提示房间占用  */  public void booking(int id){  if(rooms[id / 100 -1][id % 100 -1].getStatus()){   rooms[id / 100 - 1][id % 100 -1].setStatus(false);  //调用setStatus方法对房间状态进行修改   System.out.println("订房成功!");  }else{   System.out.println("房间已占用,请换另外一间房!");  }  }  /*  提供cancelBooking方法,用于修改房间状态  即退房  对getStatus方法的返回值使用逻辑非,查询房间状态  如果为false为占用,  */  public void cancelBooking(int id){  if( rooms[id / 100 -1][id % 100 -1].getStatus() ){   System.out.println("房间空闲,无需退房!");  }else{   rooms[id / 100 - 1][id % 100 -1].setStatus(true);   System.out.println("退房成功!");  }  } }

HotelSystem类(酒店系统类)

package com.kukudeyu.hotelsystem; import java.util.Scanner; public class HotelSystem {  public static void main(String[] args) {  Hotel hotel = new Hotel();  //创建一个酒店对象  System.out.println("----------------------------------------------------------------------------");  System.out.println("欢迎使用酒店管理系统,请认真阅读以下使用说明!");  System.out.println("功能编号:【1】查看房间列表。【2】订房。【3】退房。【4】退出酒店管理系统。");  System.out.println("----------------------------------------------------------------------------");  Scanner s = new Scanner(System.in);  while(true){   System.out.print("请输入功能编号:");   int i = s.nextInt();   if(i == 1){   hotel.print();   }else if(i == 2 ){   System.out.print("请输入要订房的房间编号:");   int roomid = s.nextInt();   hotel.booking(roomid); //调用booking方法进行订房   }else if(i == 3){   System.out.print("请输入要退订的房间编号:");   int roomid = s.nextInt();   hotel.cancelBooking(roomid); //调用cancelBooking方法进行退房   }else if(i == 4){   return;   }  }  } }

以上就是小编为大家带来的使用Java怎么编写一个酒店前台管理系统的全部内容了,希望大家多多支持亿速云!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI