Simple Hotel Reservation System
A project can not be counted as a project, is a simple hotel booking system, Sunday will look at the original content suddenly feel this is very good, just tidy up a bit.
Hotel reservation System In fact, the overall view is divided into three, one is the client, a hotel's size (that is, the hotel has several floors, how many rooms), there is a room of the type:
Hotel
Hotel Size
Several layers
Several rooms per floor
Provide a hotel room list printing method
How to book a room
The code implemented is
1 Public classhotel{2 rooms[][];3 PublicHotel () {4Rooms =NewRoom[5][10];5 for(inti=0; i < rooms.length; ++i) {6 for(intj=0; J < Rooms[i].length; ++j) {7 if(i = = 0 | | i = = 1) {8ROOMS[I][J] =NewRoom ((i+1) *100+j+1 + "", "single rooms",false);9 }Ten if(i = = 2 | | i = = 3) { OneROOMS[I][J] =NewRoom ((i+1) *100+j+1 + "", "Standard rooms",false); A } - if(i = = 4) { -ROOMS[I][J] =NewRoom ((i+1) *100+j+1 + "", "suite",false); the } - } - } - } + Public voidprint () { - for(inti=0; i < rooms.length; ++i) { + for(intj=0; J < Rooms[i].length; ++j) { ASystem.out.println (Rooms[i][j] + "" ); at } - System.out.println (); - } - } - Public voidorder (String No) { - for(inti=0; i < rooms.length; ++i) { in for(intj=0; J < Rooms[i].length; ++j) { - if(Rooms[i][j].getno (). Equals (No)) { toRooms[i][j].setuse (true); + return; - } the } * } $ }Panax Notoginseng}
Room
Room number
Room type
Whether to use
Room Number Operation method
Type Operation method
Whether to use the action method
Overwrite ToString () method
The code implemented is
1 Public classroom{2 PrivateString No;3 PrivateString type;4 Private BooleanIsuse;5 PublicGuest () {6 Super(); 7 }8 PublicThe (string no, String type,Booleanisuse) {9 Super();Ten This. No =No; One This. Type =type; A This. Isuse =Isuse; - } - PublicString Getno () { the returnNo; - } - Public voidSetno (String no) { - This. No =No; + } - PublicString GetType () { + returntype; A } at Public voidsetType (String type) { - This. Type =type; - } - Public BooleanIsuse () { - returnIsuse; - } in Public voidSetuse (Booleanisuse) { - This. Isuse =Isuse; to } + PublicString toString () { - return"[" + No + "," + type+ "," + (Isuse? ") Occupy ":" Idle ") +"] "; the } *}
Test Logic Program (client)
Instantiate a hotel class
Instantiate Room class
Call hotel room List
How to book a room
The implementation code is
1 ImportJava.util.Scanner;2 Public classclient{3 Public Static voidMain (string[] args) {4Scanner s =NewScanner (system.in);5System.out.println ("Welcome to Astro and Little Meatball Hotel management system, hotel room list" );6Hotel h =NewHotel ();7 h.print ();8 while(true){9System.out.println ("Please enter your room number") );TenString No =S.next (); One H.order (no); A h.print (); - } - } the}
So our entire system is ready and look at the results:
I'll enter a room number and look at the results.
410 This room will become
A simple hotel booking system is complete!
Welcome to Astro and Little Meatball Blog
I have been studying in Jay for one months! Still working on it!
Simple Hotel Reservation System