用Java编写一个简单的酒店管理系统,供大家参考,具体内容如下
为某个酒店编写程序:酒店管理系统,模拟订房、退房、打印所有房间状态等功能。
1、该系统的用户是:酒店前台。
2、酒店使用一个二维数组来模拟。[Room[][] rooms;]
3、酒店中的每一个房间应该是一个java对象:Room
4、每一个房间Room应该有:房间编号、房间类型、房间是否空闲.
5、系统应该对外提供的功能:
可以预定房间:用户输入房间编号,订房。
可以退房:用户输入房间编号,退房。
可以查看所有房间的状态:用户输入某个指令应该可以查看所有房间状态。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
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( "功能编号输入错误,请重新输入!" ); } }
} } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
//酒店管理系统 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++) { /*if(i==0){rooms[i][j]=new Room((i+1)*100+j+1,"单人间",true);} if(i==1){rooms[i][j]=new Room((i+1)*100+j+1,"双人间",true);} if(i==2){rooms[i][j]=new Room((i+1)*100+j+1,"三人间",true);}*/ 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+ "号房间已被退订,房间退订失败!" ); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
//房间 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? "空闲" : "占用" )+ "]" ; } } |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
原文链接:https://blog.csdn.net/weixin_47352351/article/details/114644936