Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A Reservation System Assume we have a client who requests for a reservation syst

ID: 3555506 • Letter: A

Question

A Reservation System

Assume we have a client who requests for a reservation system for a motel. The motel has 25 non-smoking rooms and 5 smoking rooms and each room can have up to 4 guests. Our client wants the reservation system to be for the same day, which means we are not concerned about the date: When making a reservation, we check for the current status of the rooms. The list of the requirements from the client are provided in the following slides.

1. The main application provides the user with four options for: making a reservation, checking-out, viewing the rooms status and an exit option.

2. When the user selects to make a reservation, a list of available rooms with the room number and smoking/non-smoking information will be displayed and the user will be asked to select a room. Once the user selects an available room, the system asks for a phone number, number of the guests (maximum four guests) and the name of the guests.

3. When the user selects to check-out, the system asks user for the room number and puts that room back to the list of available rooms. . When the user selects to view the rooms status, the system displays the information for all rooms: The room number, the smoking/non-smoking information, and the phone number and the name of all guests for the occupied rooms.

5. When the user selects to terminate, the program terminates. Otherwise, the program is always waiting for the user

Explanation / Answer

Program Code:

import java.util.Scanner;
public class ReservationSystem
{
   public static void main(String args[])
   {
       int ch=0;
       Booking bk=new Booking();
       System.out.println("Welcome to our motel!");
       System.out.println("---------------------------");
       System.out.println("---------------------------");
       System.out.println("The motel has:");
       System.out.println("*25 non-smoking rooms *5 smoking rooms (each room can have up to 4 guests)");
       System.out.println("---------------------------");
       System.out.println("---------------------------");
       while(ch!=4)
       {
           System.out.println("Please select an option:");
           System.out.println("1) Making a reservation");
           System.out.println("2) Checking-out");
           System.out.println("3) Viewing the rooms status");
           System.out.println("4) Exit");
           Scanner sc=new Scanner(System.in);
           ch=sc.nextInt();
           switch(ch)
           {
           case 1: bk.makeReservation();
                   break;
           case 2: bk.checkout();
                   break;
           case 3: bk.view();
                   break;
           case 4: System.out.println("Thank you! Have a good day");
                   break;
                   default:System.out.println("");
                   break;
           }
       }
      
   }
}
class Booking
{
   int nsRooms[]=new int[25];  
   int sRooms[]=new int[5];
   int totalGuests=0;
   int guestPerRoom=4;
   int nsAvailable=25;
   int sAvailable=5;
   int phone=0;
   String names[]=new String[120];
   Scanner sc=new Scanner(System.in);
  
   void makeReservation()
   {
       System.out.println("Room Reservation:");
       System.out.println("1.Smoking Room");
       System.out.println("2.Non Smooking Room");
       int type=sc.nextInt();
       if(type==1)
           if(sAvailable>0)
           {
               System.out.println("Please enter number of guests:");
               int checkinGuests=sc.nextInt();
               totalGuests+=checkinGuests;
               if(checkinGuests%4==0)
                   sAvailable-=checkinGuests/4;
               else
                   sAvailable-=(checkinGuests/4)+1;
               System.out.println("The number of rooms alloted to you is:"+(5-sAvailable));
               System.out.println("Please select the room numbers:");
               for(int i=0;i<(5-sAvailable);i++)
               {
                   int roomNum=sc.nextInt();
                   if(sRooms[roomNum]!=1)
                       sRooms[roomNum]=1;
                   else
                   {
                       System.out.println("Not available!Select other");
                       i--;
                   }
               }      
               System.out.println("Please enter your phone number");
               phone=sc.nextInt();
               System.out.println("Enter the names of guests:");
               for(int i=0;i<=checkinGuests;i++)
               {
                   names[i]=sc.nextLine();
               }
           }
           else
           {
               System.out.println("Sorry! No rooms available. Select another category");
               makeReservation();
           }
       else
           if(nsAvailable>0)
           {
               System.out.println("Please enter number of guests:");
               int checkinGuests=sc.nextInt();
               totalGuests+=checkinGuests;
               if(checkinGuests%4==0)
                   nsAvailable-=checkinGuests/4;
               else
                   nsAvailable-=(checkinGuests/4)+1;
               System.out.println("The number of rooms alloted to you is:"+(25-nsAvailable));
               System.out.println("Please select the room numbers:");
               for(int i=0;i<(25-nsAvailable);i++)
               {
                   int roomNum=sc.nextInt();
                   if(nsRooms[roomNum]!=1)
                       nsRooms[roomNum]=1;
                   else
                   {
                       System.out.println("Not available!Select other");
                       i--;
                   }
               }      
               System.out.println("Please enter your phone number");
               phone=sc.nextInt();
               System.out.println("Enter the names of guests:");
               for(int i=0;i<=checkinGuests;i++)
               {
                   names[i]=sc.nextLine();
               }
           }
           else
           {
               System.out.println("Sorry! No rooms available. Select another category");
               makeReservation();
           }
   }
   void checkout()
   {
       System.out.println("Please select the room type: ");
       System.out.println("1.Smoking Room");
       System.out.println("2.Non Smooking Room");
       int ch=sc.nextInt();
       System.out.println("Please enter your room number");
       int num=sc.nextInt();
       if(ch==1)
       {
           sRooms[num]=0;
           sAvailable++;
       }
       else if(ch==2)
       {
           nsRooms[num]=0;
           nsAvailable++;
       }
       else
           System.out.println("Invalid choice!");
   }
   void view()
   {
       System.out.println("The occupied smoking room numbers are");
       for(int i=0;i<5;i++)
       {
           if(sRooms[i]==1)
               System.out.println(""+i);
       }
       System.out.println("The occupied non smoking room numbers are");
       for(int i=0;i<25;i++)
       {
           if(nsRooms[i]==1)
               System.out.println(""+i);
       }
       System.out.println("Guest List:");
       for(int i=0;i<=totalGuests;i++)
           System.out.println(names[i]);
      
   }
}


Sample Output:

Welcome to our motel!
---------------------------
---------------------------
The motel has:
*25 non-smoking rooms
*5 smoking rooms
(each room can have up to 4 guests)
---------------------------
---------------------------
Please select an option:
1) Making a reservation
2) Checking-out
3) Viewing the rooms status
4) Exit
1
Room Reservation:
1.Smoking Room
2.Non Smooking Room
2
Please enter number of guests:
12
The number of rooms alloted to you is:3
Please select the room numbers:
3
6
4
Please enter your phone number
2342341
Enter the names of guests:
sdfsdf
sdfswf
tt
erter
as
dferg
tujtyj
trhrth
vbgfh
thyth
trht
fert
Please select an option:
1) Making a reservation
2) Checking-out
3) Viewing the rooms status
4) Exit
3
The occupied smoking room numbers are
The occupied non smoking room numbers are
3
4
6
Guest List:

sdfsdf
sdfswf
tt
erter
as
dferg
tujtyj
trhrth
vbgfh
thyth
trht
fert
Please select an option:
1) Making a reservation
2) Checking-out
3) Viewing the rooms status
4) Exit

4
Thank you! Have a good day

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote