Hotel Booking System
unknown
plain_text
a year ago
1.7 kB
24
Indexable
import java.util.*;
public class HotelBookingSystem {
static final int Floors=5;
static final int ROOMS_PER_FLOOR=5;
static boolean[][]rooms= new boolean[Floors][ROOMS_PER_FLOOR];
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int choice;
do{
System.out.println("\nHotel Booking System");
System.out.println("1.view room status");
System.out.println("2.Book a room ");
System.out.println("3.exit");
System.out.print("Enter your choice(1-3):");
choice=scanner.nextInt();
switch(choice)
{
case 1:
viewRooms();
break;
case 2:
bookRooms(scanner);
break;
case 3:
System.out.println("Thank you for using Hotel Booking System");
break;
default :
System.out.println("Invalid choice.Please choose between 1 and 3");
}
}while(choice !=3);
scanner.close();
}
public static void viewRooms(){
System.out.println("\n Room Status(A=available,B=Booked):");
for (int i=0;i<Floors;i++){
System.out.print("Floor"+(i+1)+":");
for (int j=0;j<ROOMS_PER_FLOOR;j++){
System.out.print(rooms[i][j]?"B":"A");
}
System.out.println();
}
}
public static void bookRooms(Scanner scanner){
System.out.print("\n Enter floor number(1-"+Floors+"):");
int floor=scanner.nextInt();
System.out.print("\n Enter room number(1-"+ROOMS_PER_FLOOR+"):");
int room=scanner.nextInt();
if(floor<1||floor>Floors||room<1||room>ROOMS_PER_FLOOR){
System.out.println("INvalid floor or room number");
return;
}
if (!rooms[floor-1][room-1]){
rooms[floor-1][room-1]=true;
System.out.println("Rooms booked sucessfully");
}else{
System.out.println("Soory,that room is already booked");
}
}
}
Editor is loading...
Leave a Comment