0% found this document useful (0 votes)
10 views3 pages

room reservation code

The document contains a Java program for a room reservation system with a menu-driven interface. Users can display room status, reserve a room, or checkout from a room. The program manages a 5x4 array representing room occupancy and includes input validation for user actions.

Uploaded by

fujiwararei556
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

room reservation code

The document contains a Java program for a room reservation system with a menu-driven interface. Users can display room status, reserve a room, or checkout from a room. The program manages a 5x4 array representing room occupancy and includes input validation for user actions.

Uploaded by

fujiwararei556
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

package aredondua;

import java.util.Scanner;

public class roomReservation {

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);

int [][] rooms = new int[5][4];

while (true){
System.out.println("\nMENU");
System.out.println("1. Display room status.");
System.out.println("2. Reserve a room.");
System.out.println("3. Checkout.");
System.out.println("4. Exit.");
System.out.print("Choose an option: ");

int choice = sc.nextInt();

if(choice == 1){
displayRoomStatus(rooms);
} else if (choice == 2){
reserveRoom(rooms, sc);
} else if (choice == 3){
checkoutRoom(rooms, sc);
} else if (choice == 4){
System.out.println("Exiting...Bye!"); break;
} else {
System.out.println("Invalid choice. Please choose
(1-4).");
}
}
sc.close();
}

public static void displayRoomStatus(int[][] rooms){


System.out.println("\nRoom Status:");
for (int i = 4; i >= 0; i--){
System.out.print("Floor " + (i + 1) + ": { ");
for (int j=0; j < 4; j++){
System.out.print(rooms[i][j]);
if(j<3){
System.out.print(". ");
}
}
System.out.println(" }");
}
}

public static void reserveRoom(int[][] rooms, Scanner sc){


System.out.print("Enter floor number (1-5): ");
int floor = sc.nextInt();
System.out.print("Enter room number (1-4): ");
int room = sc.nextInt();

if (floor < 1 || floor > 5 || room < 1 || room > 4){


System.out.println("Invalid floor and room number. Please
enter a valid number: "); return;
}

if(rooms[floor - 1][room - 1] != 0){


System.out.println("Room is currently occupied.");
} else {
rooms[floor - 1][room - 1] = 1;
System.out.println("Room reserved successfully!");
}
}

public static void checkoutRoom(int[][] rooms, Scanner sc){


System.out.print("Enter floor number (1-5): ");
int floor = sc.nextInt();
System.out.print("Enter room number (1-4): ");
int room = sc.nextInt();

if(floor < 0|| floor > 4 || room < 0||room > 3){
System.out.println("Invalid floor and room number. Please
try again."); return;
}

if(rooms[floor][room] == 1){
rooms[floor][room] = 0;
System.out.println("Checkout successful! Room is now
available.");
} else {
System.out.println("Room is already available.");
}
}
}

You might also like