Room class public class room {private string no;//Room number private string type;// Room type private boolean isuse;//room Occupancy @overridepublic string tostring () {return " Room [no= " + no + ", type= " + type + ", isuse= " + (isuse? ") Occupy ":" Idle ") + "] ";} 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;}} Hotel Class PUBLIC&NBSP;CLASS&NBSP;HOTEL&NBSP;{ROOM[][]&Nbsp;rooms;//1.1.2 floor 101-110 201-210//3.3.4 single room//5. Standard Room 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) + "", "normal room", false); } if (i==2| | i ==3) { rooms[i][j]=new room (((i+1) *100+j+1) + "", "single room", false); } Else{ rooms[i][j]=new room (((i+1) *100+j+1) + "", "Standard Room", false); } } } //Printing Room Information 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 (); } } &NBSP;&NBSP;//provides a way to book a room &NBSP;&NBSP;PUBLIC&NBSP;VOID&NBsp;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 ; } } } } //Check out 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 ; } } } }} Test class: Public class test {public static void main (String[] args) {Hotel ht = new hotel (); Ht.print ();//Reservation Ht.order ("301"); Ht.print ();//Check out ht.checkout ("301"); Ht.print ();}}
This article is from the "Gaogaozi" blog, make sure to keep this source http://hangtiangazi.blog.51cto.com/8584103/1669907
Hotel management system with array emulation in Java