需求:编程模拟酒店管理系统:预约、取消预约、显示所有房间
1需要酒店类
2需要房间类
3需要客户端类
公共类测试{
}
二分析:
客户端:
1打印好所有房间
2等待用户输入,根据输入情况判断是预约还是取消
3等待用户输入房间号码
4调用酒店预约/取消方法,传递房间号完成预约/取消功能
5完成后,作出适当指示,再次打印所有房间
6死循环依次执行以上步骤
类客户端{
}
酒店等级:
规模为:层,每层有10个房间
其中33601,2楼为标准间
3、4楼是双人房
五楼是豪华的房间
房间号码:一楼3360101、102、 110、二楼:一、202、 210 .等
默认情况下房间是空的
需要提供
房间预约方法:需要根据房间号码预约房间
如果这个房间被预订了,需要提示
取消方法:需要根据房间号码取消
如果这个房间没有被预约,需要提示
如何看所有房间:
打印格式为:
[101标准间占用] [102标准间空闲] .
[201标准间净空.
[501豪华间空着]…[510豪华间被占用]
三代码实现客户端(Client)
包热系统; import java.util.Scanner; public class client { publicstaticvoidmain (string [ ] args ) {Hotel hotel=new Hotel; sanners=newscanner(system.in ); while(true ) {System.out.println ) "请输入要选择的功能。 请确认: 1一个房间两个房间的预约。 3签出0退出”int a=s.nextInt (; sitch(a ) {case 1:hotel.show; 黑; case 2:System.out.println ('请输入房间号码); int b=s.nextInt (; hotel.order(b ); 黑; case 3:System.out.println ('请输入房间号码); int c=s.nextInt (; hotel.checkout(c ); 黑; case 0:返回; }}}} 酒店类(Hotel):
包热系统; //包名称import java.security.PublicKey; public class hotel { privateroom [ ] [ ] rooms=newroom [5] [ 10 ]; //要创建的酒店房间数量//结构方法public Hotel () )//酒店初始化for(intI=0; irooms.length; I ) for(intj=0; jrooms[i].length; j ) ) if(I=2) rooms[I][j]=newroom ) (I1 ) *100 j 1,'标准间',true ); (if ) I2I4) rooms[I][j]=newroom ) (I1 ) *100 j 1,'双人房',true ); }if(I==4) rooms[I][j]=newroom ) (I1 ) *100 j 1,“豪华间”,真); }}}} //房间里有public void show () ) (for ) ) intI=0; irooms.length; I ) for(intj=0; jrooms[i].length; j () system.out.print(rooms[I][j] ' ); }System.out.println (; (//房间保留公用void order (intnum ) if ) num/100-14||num0-19 ) {System.err.println )此房间不存在。 请输入有效的房间号码!' ); (else ) if ) num==rooms [ num/100-1 ] [ num0-1].getnumber () ) if ) rooms [ num/100-1 ] [ num0-1].isff System.out.println ('预约成功!' ); }//publicvoidcheckout(intnum ) if ) num/100-14||num0-19 ) {System.err.println )此房间不存在。 请输入有效的房间号码! ); } else { if (rooms [ num/100-1 ] [ num0-1].is flab (==true ) {System.err.println ) )此房间不需要签出! ' ); } else { rooms [ num/100-1 ] [ num0-1].set flab [ true ]; System.out.println ('签出成功! ' ); }}}} 房间类(Room):
包热系统; 公共类{ private int number; 私有字符串类型; 私有布尔实验室; //getSet方法公共输入getnumber () {return number; }publicvoidsetnumber(intnumber ) {this.number=number; }public String getType () ) {return type; }publicvoidsettype(stringtype ) {this.type=type; }公共布尔is flab () {return flab; }publicvoidsetflab(booleanflab ) {this.flab=flab; //构建方法publicroom(intnumber,String type,boolean flab ) ) {super; this.number=number; this.type=type; this.flab=flab; }@Overridepublic String toString () return'room('number''type ' ) ) flab==true? “偶像' : '占有'”; }