Traditional Culture Encyclopedia - Hotel franchise - Using object-oriented thinking to implement a hotel management system, the specific requirements are as follows: java

Using object-oriented thinking to implement a hotel management system, the specific requirements are as follows: java

package?jcon.com.help;

/** *?Customer class*?@author?Jcon * */

public?class?Customer ?{

private?String?name;

private?String?date;

private?int?days;

public? Customer(String?name,?String?date,?int?days)?{

super();

this.name?=?name;

this.date?=?date;

this.days?=?days;

}

@Override

public? String?toString()?{

return?"Customer?[name="?+?name?+?",?date="?+?date?+?",?days="? +?days

+?"]";

}

}package?jcon.com.help;

/** *?Room class*?@author?Jcon * */

public?class?Room?{

private?int?number;

private?Customer ?customer;

private?boolean?isUse?=?false;//The room is empty at first

public?int?getNumber()?{

return?number;

}

public?void?setNumber(int?number)?{

this.number?=?number;

}

public?Customer?getCustomer()?{

return?customer;

}

public?void? setCustomer(Customer?customer)?{

this.customer?=?customer;

}

public?boolean?getIsUse()?{

return?isUse;

}

public?void?setIsUse(boolean?isUse)?{

this.isUse?=?isUse;

}

}package?jcon.com.help;

import?java.util.HashMap;

import?java. util.Map;

/** *?Hotel class*?@author?Jcon * */

public?class?Hote?{

private? int?cengShu; //Floor floor

private?int?roomNumber; //Number of rooms on each floor

public?static?Map?rooms?=? new?HashMap

teger,?Room>(); //key room number, value room information

public?Hote(int?cengShu,int?roomNumber)?{

this.cengShu?= ?cengShu;

this.roomNumber?=?roomNumber;

init();

}

private?void?init( ){//Initialize, load each room information into Map

for?(int?i?=?1;?i?<=?this.cengShu;?i++)?{

for?(int?j?=?1;?j?<=?this.roomNumber;?j++)?{

String?roomNumber?=?i+""+j;

if?(j?<10)?{

roomNumber?=?i+"0"+j;

}

rooms.put(Integer.valueOf(roomNumber),?new?Room());

}

}

}

}package?jcon.com.help;

/** *?Hotel management class*?@author?Jcon * */

public?class?Manager?{

private?Hote?hote?=?new?Hote(1,?15);

//Search by room number

public?void?findRoomByNumber(int? roomNumber){

Room?room?=?hote.rooms.get(roomNumber);

if?(room?==?null)?{

System.out.println("The room number you are looking for does not exist, please make sure you entered the room number correctly!");

}else?{

if?(room .getIsUse()){

System.out.println("Room: "+roomNumber+" is already occupied, guest information: "+room.getCustomer());

}else?{

System.out.println("Room"+roomNumber+"No one has checked in yet");

}

}

}

//Find all empty rooms

public?void?findNullRoom(){

for?(Integer?key?:?hote. rooms.keySet())?{

Room?room?=?hote.rooms.get(key);

if?(room.getIsUse()?==?false )?{

System.out.println("Empty room number: "+key);

}

}

}

//Check in

public?void?in(int?roomNumber,Customer?customer){

Room?room?=?hote.rooms.get (roomNumber);

<

p> room.setCustomer(customer);

room.setIsUse(true);

room.setNumber(roomNumber);

hote.rooms.put( roomNumber,?room);

System.out.println("Room: "+roomNumber+" check-in, guest information: "+customer);

}

//Check out

public?void?out(int?roomNumber){

Room?room?=?hote.rooms.get(roomNumber);

room.setCustomer(null);

room.setIsUse(false);

hote.rooms.put(roomNumber,?room);

System.out.println("Room:"+roomNumber+"Check-out");

}

public?static?void?main(String[]?args)? {

Manager?manager?=?new?Manager();

//When a guest comes to book a room, first check if there is a vacant room

manager.findNullRoom ();

//Seeing that there are still many vacant houses, the customer wants to book room 115

Customer?customer?=?new?Customer("小白",?" Check-in on March 25th",?3);//Register guest information

manager.in(115,?customer);//Open a room

//View the current room after booking Information

manager.findRoomByNumber(115);?//For Room 115

manager.findNullRoom();?//For all empty rooms

/ /Guests who have stayed for 3 days need to check out

manager.out(115);

//View current room information after check-out

manager.findRoomByNumber( 115);?//For room 115

manager.findNullRoom();?//For all empty rooms

}

}