标签:private super return public 酒店管理
//房间类 public class Room { private String no;//房间号 private String type;//房间类型 private boolean isuse;//房间是否占用 @Override public String toString() { return "Room [no=" + no + ", type=" + type + ", isuse=" + (isuse?"占用":"空闲") + "]"; } public Room(String no, String type, boolean isuse) { super(); this.no = no; this.type = type; this.isuse = isuse; } public String getNo() { return no; } public void setNo(String no) { this.no = no; } public String getType() { return type; } public void setType(String type) { this.type = type; } public boolean isIsuse() { return isuse; } public void setIsuse(boolean isuse) { this.isuse = isuse; } } 酒店类 public class Hotel { Room[][] rooms; //1.1.2层普通间101-110 201-210 //3.3.4单人间 //5.标准间 Hotel(){ rooms = new Room[5][10]; for(int i=0;i<rooms.length;i++) for(int j=0;j<rooms[i].length;j++){ if(i==0 ||i==1){ rooms[i][j]=new Room(((i+1)*100+j+1)+"","普通间",false); } if(i==2||i ==3){ rooms[i][j]=new Room(((i+1)*100+j+1)+"","单人间",false); } else{ rooms[i][j]=new Room(((i+1)*100+j+1)+"","标准间",false); } } } //打印房间信息 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] + " "); } System.out.println(); } } //提供一个预定房间的方法 public void order(String no){ for(int i=0;i<rooms.length;i++){ for(int j=0;j<rooms[i].length;j++){ if(rooms[i][j].getNo().equals(no)){ rooms[i][j].setIsuse(true); return ; } } } } //退房 public void checkout(String no){ for(int i=0;i<rooms.length;i++){ for(int j=0;j<rooms[i].length;j++){ if(rooms[i][j].getNo().equals(no)){ rooms[i][j].setIsuse(false); return ; } } } } } 测试类: public class Test { public static void main(String[] args){ Hotel ht = new Hotel(); ht.print(); //订房 ht.order("301"); ht.print(); //退房 ht.checkout("301"); ht.print(); } }
本文出自 “gaogaozi” 博客,请务必保留此出处http://hangtiangazi.blog.51cto.com/8584103/1669907
标签:private super return public 酒店管理
原文地址:http://hangtiangazi.blog.51cto.com/8584103/1669907