Simple hotel management system

hotel

package 酒店;

public class hotel {
	room [][] r ;
	hotel(){
		r =new room[5][10];
		for(int i=0; i<r.length; i++) {
			for(int j=0; j<r[i].length; j++) {
				if(i==0||i==1) {
					r[i][j] =new room(((i+1)*100+j+1)+"","标准间",false);
				}
				if(i==2||i==3) {
					r[i][j] =new room(((i+1)*100+j+1)+"","双人间",false);
				}
				if(i==4) {
					r[i][j] =new room(((i+1)*100+j+1)+"","豪华间",false);
				}
			}
		}
	}
	public void print() {
		for(int i=0; i<r.length; i++) {
			for(int j=0; j<r[i].length; j++) {
				System.out.print(r[i][j]);
			}
			System.out.println();
		}
	}
	public void order(String num) {
		for(int i=0; i<r.length; i++) {
			for(int j=0; j<r[i].length; j++) {
				if(r[i][j].getNum().equals(num)) {
					r[i][j].setIsuser(true);
					return ;
				}
			}
		}
	}
}

room

package 酒店;

public class room {
	String num;
	String type;
	boolean isuser;
	public room() {
		super();
	}
	public room(String num, String type, boolean isuser) {
		super();
		this.num = num;
		this.type = type;
		this.isuser = isuser;
	}

	public String getNum() {
		return num;
	}

	public void setNum(String num) {
		this.num = num;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public boolean isIsuser() {
		return isuser;
	}

	public void setIsuser(boolean isuser) {
		this.isuser = isuser;
	}

	public String  toString () {
		return "["+num+","+type+","+(isuser?"占用":"空闲")+"]";
	}
}

test

public class test {
	public static void main(String[] args) {
		
		Scanner s =new Scanner(System.in);
		System.out.println("欢迎来到酒店 管理系统");
		hotel h =new hotel();
		while(true) {
		System.out.println("请输入房间编号");
		String num =s.next();
		h.order(num);
		h.print();
		}
}
}
Released eight original articles · won praise 0 · Views 17

Guess you like

Origin blog.csdn.net/richpersion/article/details/105125657