Question

making a file You are tasked with creating a text-based program for storing data on Hotel...

making a file

You are tasked with creating a text-based program for storing data on Hotel Room Bookings - however, as this is a comparative languages course, you will be creating the same application in the following three programming languages:

• Java,

• Python, and

• Lisp

As you implement the application in each language you should keep notes on:

- The features of the languages used,

- Which features you found useful, and

- Any issues or complications which arose due to the complexity or lack of any language features.

A brief discussion document based on these programming features for each individual language accompanying each implementation is required. Finally, a comparative overview of the languages highlighting how they were suitable or not suitable for the creating this type of application is also required.

It is recommended that the first version of the application you write is in the programming language which is most familiar to you. This will help you to have a working 'template' for storing room bookings which you can then translate into the other programming languages.

Program Specification

When the program first launches, there is a menu which allows the user to select one of the following five options:

1.) Add a guest

2.) Add a room

3.) Add a booking

4.) View bookings

5.) Quit

The functionality of these options is as follows:

1.) When users add a guest they provide a name which is stored in some manner of array or list. Guests are assigned a unique ID value where the first guest added is assigned the ID value 1, the second guest added is assigned the ID value 2 and so on.

2.) When users add a room they provide a room number and a room capacity (i.e. how many people can stay in the room at any one time) which is stored in some manner of array or list. Rooms have a property which indicates if they are booked or not for any given date – please see the Room Booking Dates section below for some guidance on the easiest way to implement this.

3.) When users add a booking they provide a guest ID, room number, the number of guests staying and finally a check-in date and check-out date. To successfully create a room booking: • The guest ID must be a guest which is registered on the system, • The room number must be of a room that exists, • The room must be able to accommodate the number of people in the booking (i.e. if the room capacity is for 2 people and the booking has 4 people staying then the booking must be refused), and finally • The room must be available on the dates requested.

4.) When users views bookings they have the option to: a. View guest bookings, or b. View room bookings. If the user opts to show guest bookings then they are prompted to enter the guest ID - and then any bookings made by that guest are displayed including: - The guest’s name, - Which room number they booked & number of guests staying, and - The check-in and check-out dates. If the user opts to show room bookings then they are prompted to enter a room number - and then any bookings for that room within the current year are displayed, including: - The guest’s name, - The number of guests staying, and - The check-in and check-out dates.

5.) When a user chooses to Quit the program terminates with a goodbye message. Each implementation of your project (in each of the three languages you choose) should aim to closely match the setup and structure of the program as shown in the example output on the following pages.

You may wish create separate Guest, Room and potentially Booking classes as part of your implementations, but you do not have to. You may also wish to add code to pre-create a number of guests, rooms and bookings on each run of your code to avoid the need to type in these details over and over when testing your program. If you do so, please comment out these pre-defined entries before

Room Booking Dates

Dates can be a complex subject to do correctly in programming because we often want to calculate how many days are between dates, and there are issues like date formats (dd/mm/yy? mm/dd/yyyy?) to consider as well as leap years where February has 29 days instead of the usual 28 and so on.

Some programming languages come with built-in classes to work with dates – and you may use them if you wish. In fact, you are encouraged to use them as they are precisely what you would use when working in the real world, so experience in them now will increase your programming knowledge!

However, to keep things simple, our room booking system will only allow bookings within the current year, and the easiest way to do that is to store dates as the number of the day between 1 and 365. So, day 18 would be the 18th of January (which has 31 days), day 32 would be the 1st of February, and so on.

As such, one way to keep track of whether a room is booked or not for a current day would be for each room to have an array of 365 boolean values which are all set to false (i.e. room is not booked for that particular day) when the room is first created. Then, because users don’t like entering dates as values between 1 and 365, we could have four utility methods:

- int dateToDayNumber(int month, int day),

- int dayNumberToMonth(int dayNumber),

- int dayNumberToDayOfMonth(int dayNumber), and

- bool setBooked(int startDayNumber, int endDayNumber).

Example code for the first tree of these methods, written in a Java-like syntax, is provided on the following page – you should write the setBooked method yourself. The above setBooked method signature assumes you are running the method on a Room object – if you are not, then you will also have to pass in the room number so you know which room’s booked array to modify!

The setBooked method should check if the room is booked for each day between the start and end dates (inclusive) to ensure the room is available. If the room is not available on a day the method returns false, but if the room is available between the start and end dates then it should be set to booked for each day requested and the method should return true to indicate success.

Bookings are not required to have booking ID values assigned to them, but you may add them if you wish as they may be useful to later functionality.

Example Program Output Startup and add guest example output

-----------------------------------------------

------ Welcome to UniSA Hotel Bookings -------

-----------------------------------------------

Main Menu - please select an option:

1.) Add guest

2.) Add room

3.) Add booking

4.) View bookings

5.) Quit

1 Please enter guest name:

Alan

Guest Alan has been created with guest ID: 1

Would you like to [A]dd a new guest or [R]eturn to the previous menu?

A Please enter guest name:

Brenda

Guest Brenda has been created with guest ID: 2

Would you like to [A]dd a new guest or [R]eturn to the previous menu?

R

Add room example output Main Menu - please select an option:

1.) Add guest

2.) Add room

3.) Add booking

4.) View bookings

5.) Quit

2 Please enter room number:

101

Please enter room capacity:

2

Would you like to [A]dd a new room or [R]eturn to the previous menu?

A

Please enter room number:

101

Room already exists. Please enter room number:

202

Please enter room capacity:

5

Would you like to [A]dd a new room or [R]eturn to the previous menu?

R

Add booking example output

Main Menu - please select an option:

1.) Add guest

2.) Add room

3.) Add booking

4.) View bookings

5.) Quit

3

Please enter guest ID:

99

Guest does not exist. Please enter guest ID:

1

Please enter room number:

66

Room does not exist. Please enter room number:

101

Please enter number of guests:

3

Guest count exceeds room capacity of:

2

Please enter room number:

202

Please enter number of guests:

3

Please enter check-in month:

15

Invalid month. Please enter check-in month:

8

Please enter check-in day:

55

Invalid day. Please enter check-in day:

28

Please enter check-out month:

8

Please enter check-out day:

30

*** Booking successful! ***

Would you like to [A]dd a new booking or [R]eturn to the previous menu?

A

Please enter guest ID:

2

Please enter room number:

202

Please enter number of guests:

1

Please enter check-in month:

8

Please enter check-in day:

29

Please enter check-out month:

8

Please enter check-out day:

30

Room is not available during that period. Please enter new room number:

101

*** Booking successful! ***

View bookings example output

Main Menu - please select an option:

1.) Add guest

2.) Add room

3.) Add booking

4.) View bookings

5.) Quit

4

Would you like to view [G]uest bookings, [R]oom booking, or e[X]it?

G

Please enter guest ID:

99

Guest does not exist. Please enter guest ID:

1

Guest 1 : Alan Booking : Room 202, 3 guest(s) from 08/28 to 08/30. Would you like to view [G]uest bookings, [R]oom booking, or e[X]it?

R

Please enter room number:

999

Room does not exist. Please enter room number:

101

Room 101 bookings: Guest 2 – Brenda, 1 guest(s) from 08/29 to 08/30. Would you like to view [G]uest bookings, [R]oom booking, or e[X]it?

X

Quit example output

Main Menu - please select an option:

1.) Add guest

2.) Add room

3.) Add booking

4.) View bookings

5.) Quit

5

Thanks for using UniSA Hotel Bookings!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Booking.java

Room.java

Guest.java

Output:-

Text file for HotelRoomBooking.java

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class HotelRoomBooking {

   public static void main(String[] args) {
       // TODO Auto-generated method stub

       System.out.println("-----------------------------------------------\r\n"
               + "------ Welcome to UniSA Hotel Bookings -------\r\n"
               + "-----------------------------------------------");
       List<Guest> guestList = new ArrayList<>();
       List<Room> roomList = new ArrayList<>();
       List<Integer> roomNos = new ArrayList<>();
       List<Integer> guestIdList = new ArrayList<>();
       List<Booking> bookingList = new ArrayList<>();
       int gc = 0;
       loop1: while (true) {
           Scanner sc = new Scanner(System.in);

           System.out.println("1.) Add a guest\r\n" + "2.) Add a room\r\n" + "3.) Add a booking\r\n"
                   + "4.) View bookings\r\n" + "5.) Quit");

           int n = sc.nextInt();

           if (n == 1) {
               loop2: while (true) {
                   gc++;
                   System.out.println("Please enter guest name:");
                   String guestname = sc.next();
                   Guest guest = new Guest();
                   guest.setName(guestname);
                   guest.setId(gc);
                   guestList.add(guest);
                   guestIdList.add(gc);// tracking guest id
                   System.out.println("Guest " + guestname + " has been created with guest ID:" + gc);
                   System.out.println("Would you like to [A]dd a new room or [R]eturn to the previous menu?");
                   String val = sc.next();
                   if (val.equals("A")) {
                       continue loop2;
                   } else if (val.equals("R")) {
                       break loop2;
                   }

               } // while
           }

           else if (n == 2) {
               loop3: while (true) {
                   System.out.println("Please enter room number:");
                   int room_number = sc.nextInt();

                   // checking if rom already filled
                   if (roomNos.contains(room_number)) {
                       System.out.print("Room already exists.");
                       continue loop3;
                   }

                   System.out.println("Please enter room capacity:");
                   int room_cap = sc.nextInt();
                   Room room = new Room();
                   room.setRoomNo(room_number);
                   room.setRoomcapacity(room_cap);
                   roomList.add(room);

                   roomNos.add(room_number);

                   System.out.println("Would you like to [A]dd a new room or [R]eturn to the previous menu?");
                   String val = sc.next();
                   if (val.equals("A")) {
                       continue loop3;
                   } else if (val.equals("R")) {
                       break loop3;
                   }
               }
           }
           // third condition
           else if (n == 3) {
               loop4: while (true) {
                   System.out.println("Please enter guest ID:");
                   int guestId = sc.nextInt();
                   if (!guestIdList.contains(guestId)) {
                       System.out.print("Guest does not exist.");
                       continue loop4;
                   }
                   System.out.println("Please enter room number:");
                   int room_number = sc.nextInt();

                   if (!roomNos.contains(room_number)) {
                       System.out.println("Room does not exist");
                       continue loop4;
                   }
                   System.out.println("Please enter number of guests:");
                   int guestCount = sc.nextInt();

                   for (Room room : roomList) {
                       if (room_number == room.getRoomNo()) {
                           if (guestCount > room.getRoomcapacity()) {
                               System.out
                                       .print("Guest count exceeds room capacity of:" + "\n" + room.getRoomcapacity());
                               continue loop4;
                           }
                       }
                   }

                   System.out.println("Please enter check-in month:");
                   int checkInMonth = sc.nextInt();

                   if (checkInMonth < 1 && checkInMonth > 12) {
                       System.out.println("Invalid month.");
                       continue loop4;
                   }

                   System.out.println("Please enter check-in day:");
                   int checkInDay = sc.nextInt();

                   if (checkInDay < 1 && checkInDay > 30) {
                       System.out.println("Invalid day.");
                       continue loop4;
                   }

                   // checkout

                   System.out.println("Please enter check-out month:");
                   int checkOutMonth = sc.nextInt();

                   if (checkOutMonth < 1 && checkOutMonth > 12) {
                       System.out.println("Invalid month.");
                       continue loop4;
                   }

                   System.out.println("Please enter check-out day:");
                   int checkOutDay = sc.nextInt();

                   if (checkOutDay < 1 && checkOutDay > 30) {
                       System.out.println("Invalid day.");
                       continue loop4;
                   }

                   Booking booking = new Booking();
                   booking.setRoom_number(room_number);
                   booking.setGuestId(guestId);
                   booking.setGuestCount(guestCount);
                   booking.setCheckInMonth(checkInMonth);
                   booking.setCheckInDay(checkInDay);
                   booking.setCheckOutMonth(checkOutMonth);
                   booking.setCheckOutDay(checkOutDay);
                   bookingList.add(booking);

                   System.out.println("*** Booking successful! ***");
                   System.out.println("Would you like to [A]dd a new room or [R]eturn to the previous menu?");
                   String val = sc.next();
                   if (val.equals("A")) {
                       continue loop4;
                   } else if (val.equals("R")) {
                       break loop4;
                   }

               } // loop4

           } // if

           else if (n == 4) {
               loop5: while (true) {

                   System.out.println("Would you like to view [G]uest bookings, [R]oom booking, or e[X]it?");

                   String val = sc.next();
                   if (val.equals("G")) {
                       System.out.println("Please enter guest ID:");
                       int guestId = sc.nextInt();
                       if (!guestIdList.contains(guestId)) {
                           System.out.print("Guest does not exist.");
                           continue loop5;
                       } else {
                           for (Guest guest : guestList) {
                               if (guestId == guest.getId()) {
                                   System.out.print("Guest " + guestId + " " + guest.getName() + " ");// from guest

                               }
                           }

                           for (Booking booking : bookingList) {
                               if (guestId == booking.getGuestId()) {
                                   System.out.print("Room " + booking.getRoom_number() + ", " + booking.getGuestCount()
                                           + " guest(s) from " + booking.getCheckInMonth() + "/"
                                           + booking.getCheckInDay() + " to " + booking.getCheckOutMonth() + "/"
                                           + booking.getCheckOutDay() + "\n");// from guest

                               }
                           }
                       }
                   } else if (val.equals("R")) {
                       continue loop1;

                   } else if (val.equals("X")) {
                       break loop1;
                   }
               } // loop5

           } // n==4 if

       } // loop1

       System.out.println("Thanks for using UniSA Hotel Bookings!");
   }

}


//Guest.java


public class Guest {
  
   private String name;
   private int id;
  
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public int getId() {
       return id;
   }
   public void setId(int id) {
       this.id = id;
   }
  

}

//Room.java


public class Room {

   private int roomNo;
   private int roomcapacity;
   private boolean booked;
   public int getRoomNo() {
       return roomNo;
   }
   public void setRoomNo(int roomNo) {
       this.roomNo = roomNo;
   }
   public int getRoomcapacity() {
       return roomcapacity;
   }
   public void setRoomcapacity(int roomcapacity) {
       this.roomcapacity = roomcapacity;
   }
   public boolean isBooked() {
       return booked;
   }
   public void setBooked(boolean booked) {
       this.booked = booked;
   }
  
}

//Booking.java


public class Booking {
private int guestId;
private int room_number;
private int guestCount;
private int checkInMonth;
private int checkOutMonth;
private int checkInDay;
private int checkOutDay;
public int getGuestId() {
   return guestId;
}
public void setGuestId(int guestId) {
   this.guestId = guestId;
}
public int getRoom_number() {
   return room_number;
}
public void setRoom_number(int room_number) {
   this.room_number = room_number;
}
public int getGuestCount() {
   return guestCount;
}
public void setGuestCount(int guestCount) {
   this.guestCount = guestCount;
}
public int getCheckInMonth() {
   return checkInMonth;
}
public void setCheckInMonth(int checkInMonth) {
   this.checkInMonth = checkInMonth;
}
public int getCheckOutMonth() {
   return checkOutMonth;
}
public void setCheckOutMonth(int checkOutMonth) {
   this.checkOutMonth = checkOutMonth;
}
public int getCheckInDay() {
   return checkInDay;
}
public void setCheckInDay(int checkInDay) {
   this.checkInDay = checkInDay;
}
public int getCheckOutDay() {
   return checkOutDay;
}
public void setCheckOutDay(int checkOutDay) {
   this.checkOutDay = checkOutDay;
}
  
  
  
}

Package structure:-

Add a comment
Know the answer?
Add Answer to:
making a file You are tasked with creating a text-based program for storing data on Hotel...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program in Java, Python and Lisp When the program first launches, there is a...

    Write a program in Java, Python and Lisp When the program first launches, there is a menu which allows the user to select one of the following five options: 1.) Add a guest 2.) Add a room 3.) Add a booking 4.) View bookings 5.) Quit The functionality of these options is as follows: 1.) When users add a guest they provide a name which is stored in some manner of array or list. Guests are assigned a unique ID...

  • In this lab, you will create a program to help travelers book flights and hotel stays that will b...

    In this lab, you will create a program to help travelers book flights and hotel stays that will behave like an online booking website. The description of the flights and hotel stays will be stored in two separate String arrays. In addition, two separate arrays of type double will be used to store the prices corresponding to each description. You will create the arrays and populate them with data at the beginning of your program. This is how the arrays...

  • The owner of the B&B would like to know how much each room contributes to total...

    The owner of the B&B would like to know how much each room contributes to total revenues. In this regard, she would like a list of rooms (room ID and room name), and how much revenue each room brought in for 2019 (even including rooms that did not bring in any revenue; i.e., they weren't booked in 2019). Room revenue (for a given booking) are found in the total field in Bookings. You only need to consider bookings where check-in...

  • the first question java code eclipse app the second question is java fx gui caculator please...

    the first question java code eclipse app the second question is java fx gui caculator please fast 1. Create project called "YourFirstName_QUID'. Eg. Aliomar_202002345 2. Create two package Q1 and Q2. 3. Add your name and studentID as comments on the top of each Java source file you submit. Question 1. Bookings APP [80 Points-six parts] Implement the following hotel booking system. Use the following class diagram to understand the structure of the system's classes, their attributes operations (or methods),...

  • -can you change the program that I attached to make 3 file songmain.cpp , song.cpp ,...

    -can you change the program that I attached to make 3 file songmain.cpp , song.cpp , and song.h -I attached my program and the example out put. -Must use Cstring not string -Use strcpy - use strcpy when you use Cstring: instead of this->name=name .... use strcpy ( this->name, name) - the readdata, printalltasks, printtasksindaterange, complitetasks, addtasks must be in the Taskmain.cpp - I also attached some requirements below as a picture #include <iostream> #include <iomanip> #include <cstring> #include <fstream>...

  • Why does my program generate [] when viewing all guests names? ----------------------------------------------- import java.util.*; public class...

    Why does my program generate [] when viewing all guests names? ----------------------------------------------- import java.util.*; public class Delete extends Info { String name; int Id; int del; public Delete() { } public void display() { Scanner key = new Scanner(System.in); System.out.println("Input Customer Name: "); name = key.nextLine(); System.out.println("Enter ID Number: "); Id = key.nextInt(); System.out.println("Would you like to Delete? Enter 1 for yes or 2 for no. "); del = key.nextInt(); if (del == 1) { int flag = 0; //learned...

  • For this project, you are tasked with creating a text-based, basic String processing program that performs...

    For this project, you are tasked with creating a text-based, basic String processing program that performs basic search on a block of text inputted into your program from an external .txt file. After greeting your end user for a program description, your program should prompt the end user to enter a .txt input filename from which to read the block of text to analyze. Then, prompt the end user for a search String. Next, prompt the end user for the...

  • In this assignment, we will be making a program that reads in customers' information, and create...

    In this assignment, we will be making a program that reads in customers' information, and create a movie theatre seating with a number of rows and columns specified by a user. Then it will attempt to assign each customer to a seat in a movie theatre. 1. First, you need to add one additional constructor method into Customer.java file. Method Description of the Method public Customer (String customerInfo) Constructs a Customer object using the string containing customer's info. Use the...

  • C++ program Write a C++ program to manage a hospital system, the system mainly uses file...

    C++ program Write a C++ program to manage a hospital system, the system mainly uses file handling to perform basic operations like how to add, edit, search, and delete record. Write the following functions: 1. hospital_menu: This function will display the following menu and prompt the user to enter her/his option. The system will keep showing the menu repeatedly until the user selects option 'e' from the menu. Arkansas Children Hospital a. Add new patient record b. Search record c....

  • Please help me write a program flowchart! I have been struggling for quite some time, and...

    Please help me write a program flowchart! I have been struggling for quite some time, and mainly I need the answer. Thank you ! room Hef main(); #run order: date waitlist budget result numGuests = guests() weekDay = date() waitList = waitlist(weekDay) hotelBudget - budget() print("Day:, displayWeek (weekDay)) print("Budget: ", hotel Budget) result(waitList, numGuests, room(numGuests, hotelBudget)) def guests(): numGuests - while numGuests <=@ or numGuests > 8: try: numGuests = (int(input("Please enter number of guests:"))) if numGuests > 8: print("Maximum...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT