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
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.
Screenshot
Program
Guest.java
public class Guest {
//Instance variable
private static int cnt=0;
private int ID=0;;
private String name;
//Constructor
public Guest(String name) {
ID=++cnt;
this.name=name;
}
//Getters and setters
public int getID() {
return ID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Room.java
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
public class Room {
//Instance variable
private String roomNum;
private int capacity;
Map<Date,Date> bookingDates;
//Constructor
public Room(String roomNum,int capacity) {
this.roomNum=roomNum;
this.capacity=capacity;
bookingDates=new
LinkedHashMap<Date,Date>();
}
//Method to add booking
public void add(Date startDate,Date endDate) {
bookingDates.put(startDate,endDate);
}
//Getters
public String getRoomNum() {
return roomNum;
}
public int getCapacity() {
return capacity;
}
public Map<Date, Date> getBookingDates() {
return bookingDates;
}
}
Booking.java
import java.util.Date;
public class Booking {
//Instance variables
private Guest guest;
private String roomNum;
private int guestCnt;
private Date checkIn;
private Date checkOut;
//Constructor
public Booking(Guest g,String room,int cnt,Date
in,Date out) {
guest=g;
roomNum=room;
guestCnt=cnt;
checkIn=in;
checkOut=out;
}
//Get id method
public int getId() {
return guest.getID();
}
//Get room number
public String getRoom() {
return
roomNum;
}
//Get check in date
@SuppressWarnings("deprecation")
public int year() {
return
checkIn.getYear();
}
@Override
public String toString() {
return "Guest Name:
"+guest.getName()+",\tRoom Number: "+roomNum+",\tGuest count:
"+guestCnt+",\tCheckIn Date: "+checkIn+",\tCheckOut Date:
"+checkOut;
}
}
BookingTest.java
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Map;
import java.util.Scanner;
public class BookingTest {
//Key board read
private static Scanner sc=new
Scanner(System.in);
public static void main(String[] args) throws
ParseException {
//For storage
ArrayList<Guest>guests=new
ArrayList<Guest>();
ArrayList<Room>rooms=new
ArrayList<Room>();
ArrayList<Booking>bookings=new
ArrayList<Booking>();
//Get user choice
int opt=getMenu();
//Loop until exit
while(opt!=5) {
sc.nextLine();
//Execute each
options
if(opt==1)
{
addGuest(guests);
}
else if(opt==2)
{
addRoom(rooms);
}
else if(opt==3)
{
addBooking(bookings,rooms,guests);
}
else if(opt==4)
{
System.out.println("\nVIEW TWO WAYS:-\na. View
guest bookings, or b. View room bookings");
char ch=sc.nextLine().charAt(0);
if(ch=='a') {
viewByGuest(bookings);
}
else {
viewByRoom(bookings);
}
}
System.out.println();
//Repetition
opt=getMenu();
}
//Exit message
System.out.println("\n****GOOD
BYE***");
}
//Method to get menu
private static int getMenu() {
System.out.println("OPTIONS:-");
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");
System.out.print("Enter your
option:-");
int opt=sc.nextInt();
while(opt<1 || opt>5) {
System.out.println("ERRROR!!!Option must be 1-5");
System.out.print("Enter your option:-");
opt=sc.nextInt();
}
return opt;
}
//Method to add a guest
public static void
addGuest(ArrayList<Guest>guests) {
System.out.print("\nEnter name of
the guest: ");
guests.add(new
Guest(sc.nextLine()));
}
//Method to add a room
public static void addRoom(ArrayList<Room>rooms)
{
System.out.print("\nEnter room
number: ");
String rNum=sc.nextLine();
System.out.println("Enter capacity
of the room: ");
int cap=sc.nextInt();
sc.nextLine();
Boolean check=false;
for(int i=0;i<rooms.size();i++)
{
if(rooms.get(i).getRoomNum().equalsIgnoreCase(rNum)) {
check=true;
}
}
if(!check) {
rooms.add(new
Room(rNum,cap));
}
else {
System.out.println("Room already exist!!!");
}
}
//Method to add a booking
public static void
addBooking(ArrayList<Booking>bookings,ArrayList<Room>rooms,ArrayList<Guest>guests)
throws ParseException {
//Date formatting
SimpleDateFormat formatter= new
SimpleDateFormat("dd-mm-yyyy");
//Prompt for booking data
System.out.print("\nEnter Guest Id:
");
int id=sc.nextInt();
sc.nextLine();
System.out.print("Enter room
number: ");
String rNum=sc.nextLine();
System.out.print("Enter count of
the guests: ");
int cnt=sc.nextInt();
sc.nextLine();
System.out.print("Enter check in
date in (dd-mm-yyyy): ");
Date
in=formatter.parse(sc.nextLine());
System.out.print("Enter check out
date in (dd-mm-yyyy): ");
Date
out=formatter.parse(sc.nextLine());
boolean
guestCheck=false,roomCheck=false,guestCntCheck=false;
//Loop through to check guest id
correct
for(int i=0;i<guests.size();i++)
{
if(guests.get(i).getID()==id) {
guestCheck=true;
//Loop through to check room number
correct
for(int j=0;j<rooms.size();j++) {
if(rooms.get(j).getRoomNum().equalsIgnoreCase(rNum)) {
roomCheck=true;
//Check
capacity of room
if(rooms.get(j).getCapacity()>=cnt) {
guestCntCheck=true;
//Date checking
Map<Date,Date>
temp=rooms.get(j).getBookingDates();
if(temp.size()==0) {
bookings.add(new
Booking(guests.get(i),rNum,cnt,in,out));
rooms.get(j).add(in,out);
System.out.println("Booked
successfully!!!");
return;
}
else {
//Loop through each
date
for(Date key:temp.keySet())
{
if(key.compareTo(in)==0 || key.compareTo(in)>0) {
if(key.compareTo(out)==0 ||
key.compareTo(out)<0) {
System.out.println("Booking
cancelled!!! Room is already booked");
return;
}
}
}
bookings.add(new
Booking(guests.get(i),rNum,cnt,in,out));
rooms.get(j).add(in,out);
System.out.println("Booked
successfully!!!");
return;
}
}
}
}
}
}
//Error messages
if(!guestCheck) {
System.out.println("Booking cancelled!!!Guest id "+id+" not present
in register");
}
else if(!roomCheck) {
System.out.println("Booking cancelled!!!Room number "+rNum+" not
present in register");
}
else if(!guestCntCheck) {
System.out.println("Booking cancelled!!!Capacity of room is less
than requirement");
}
}
//Method to view by guests
public static void
viewByGuest(ArrayList<Booking>bookings) {
System.out.println("\nEnter guest
id: ");
int id=sc.nextInt();
boolean check=false;
for(int
i=0;i<bookings.size();i++) {
if(bookings.get(i).getId()==id) {
System.out.println(bookings.get(i));
check=true;
}
}
if(!check) {
System.out.println("Guest id "+id+" not found in the booking
list!!!");
}
}
//Method to view by rooms
@SuppressWarnings("deprecation")
public static void
viewByRoom(ArrayList<Booking>bookings) {
System.out.println("\nEnter room number: ");
String
rNum=sc.nextLine();
boolean
check=false;
for(int
i=0;i<bookings.size();i++) {
if(bookings.get(i).getRoom().equalsIgnoreCase(rNum) &&
bookings.get(i).year()==new Date().getYear() ) {
System.out.println(bookings.get(i));
check=true;
}
}
if(!check)
{
System.out.println("Room number "+rNum+" not
found in the booking list!!!");
}
}
}
-------------------------------------------------------------------------------------------------
Output
OPTIONS:-
1.) Add a guest
2.) Add a room
3.) Add a booking
4.) View bookings
5.) Quit
Enter your option:-1
Enter name of the guest: Macheal Garner
OPTIONS:-
1.) Add a guest
2.) Add a room
3.) Add a booking
4.) View bookings
5.) Quit
Enter your option:-2
Enter room number: 101
Enter capacity of the room:
2
OPTIONS:-
1.) Add a guest
2.) Add a room
3.) Add a booking
4.) View bookings
5.) Quit
Enter your option:-2
Enter room number: 102
Enter capacity of the room:
4
OPTIONS:-
1.) Add a guest
2.) Add a room
3.) Add a booking
4.) View bookings
5.) Quit
Enter your option:-3
Enter Guest Id: 2
Enter room number: 101
Enter count of the guests: 2
Enter check in date in (dd-mm-yyyy): 14-05-2015
Enter check out date in (dd-mm-yyyy): 14-06-2015
Booking cancelled!!!Guest id 2 not present in register
OPTIONS:-
1.) Add a guest
2.) Add a room
3.) Add a booking
4.) View bookings
5.) Quit
Enter your option:-3
Enter Guest Id: 1
Enter room number: 103
Enter count of the guests: 2
Enter check in date in (dd-mm-yyyy): 14-02-2019
Enter check out date in (dd-mm-yyyy): 16-02-2019
Booking cancelled!!!Room number 103 not present in register
OPTIONS:-
1.) Add a guest
2.) Add a room
3.) Add a booking
4.) View bookings
5.) Quit
Enter your option:-3
Enter Guest Id: 1
Enter room number: 101
Enter count of the guests: 3
Enter check in date in (dd-mm-yyyy): 14-02-2019
Enter check out date in (dd-mm-yyyy): 16-02-2019
Booking cancelled!!!Capacity of room is less than requirement
OPTIONS:-
1.) Add a guest
2.) Add a room
3.) Add a booking
4.) View bookings
5.) Quit
Enter your option:-3
Enter Guest Id: 1
Enter room number: 101
Enter count of the guests: 2
Enter check in date in (dd-mm-yyyy): 14-02-2019
Enter check out date in (dd-mm-yyyy): 16-02-2019
Booked successfully!!!
OPTIONS:-
1.) Add a guest
2.) Add a room
3.) Add a booking
4.) View bookings
5.) Quit
Enter your option:-4
VIEW TWO WAYS:-
a. View guest bookings, or b. View room bookings
a
Enter guest id:
1
Guest Name: Macheal Garner, Room Number:
101, Guest count: 2, CheckIn Date: Mon Jan
14 00:02:00 IST 2019, CheckOut Date: Wed Jan 16
00:02:00 IST 2019
OPTIONS:-
1.) Add a guest
2.) Add a room
3.) Add a booking
4.) View bookings
5.) Quit
Enter your option:-4
VIEW TWO WAYS:-
a. View guest bookings, or b. View room bookings
a
Enter guest id:
2
Guest id 2 not found in the booking list!!!
OPTIONS:-
1.) Add a guest
2.) Add a room
3.) Add a booking
4.) View bookings
5.) Quit
Enter your option:-4
VIEW TWO WAYS:-
a. View guest bookings, or b. View room bookings
b
Enter room number:
101
Guest Name: Macheal Garner, Room Number:
101, Guest count: 2, CheckIn Date: Mon Jan
14 00:02:00 IST 2019, CheckOut Date: Wed Jan 16
00:02:00 IST 2019
OPTIONS:-
1.) Add a guest
2.) Add a room
3.) Add a booking
4.) View bookings
5.) Quit
Enter your option:-4
VIEW TWO WAYS:-
a. View guest bookings, or b. View room bookings
b
Enter room number:
102
Room number 102 not found in the booking list!!!
OPTIONS:-
1.) Add a guest
2.) Add a room
3.) Add a booking
4.) View bookings
5.) Quit
Enter your option:-5
****GOOD BYE***
Write a program in Java, Python and Lisp When the program first launches, there is a...
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...
requires python to answer (a) A school library has 3 study rooms available for students to book during its opening hours, on a first-come-first-serve basis. Assume there is no pre-booking, that is, the study rooms can be booked only on the day of usage itself. A library staff should be able to select to perform one of the following actions: Book a room o If there is no available room, the message: No study room available currently is displayed and...
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),...
Variable 2 hotel 3 is canceled lead time 5 arrival date_year 6 arrival_date_month 7 arrival date week number 8 arrival_date_day_of_month stays_in_weekend_nights stays_in_week_nights 10 11 adults 12 children 13 babies meal Description Hotel (H1 - Resort Hotel or H2 = City Hotel) Value indicating if the booking was canceled (1) or not (0) Number of days that elapsed between the entering date of the booking into the PMS and the arrival date Year of arrival date Month of arrival date Week...
Write this program using python. In your program, when you prompt users for values, only prompt them to enter one value at a time. Here is a sample of what your program should look like. Sample Program Run (User input in bold) What is the length of the room (in feet)? 50 What is the width of the room (in feet)? 30 What is the length of the table (in feet)? 8 What is the width of the table (in...
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...
Please help me to write a c++ program that will Implement a HotelRoom class, with private data members: the room number, room capacity (representing the maximum number of people the room can accommodate), the occupancy status (0 or the number of occupants in the room), the daily room rate. Member functions include: • a 4-argument constructor that initializes the four data members of the object being created (room number, room capacity, room rate, occupancy status) to the constructor's arguments. The...
Write a program with java editor is about the student system, you need to write some simple and uncomplicated student information, then use 2D-Aarraylist to edit some simple code, and then when the user chooses the command, it must be casually selected, according to the user. The request to execute the command, for example when the user selects (student, id, gpa, etc.) wants to remove it. Have any questions to ask me, because my homework is not required to add...
You are hired by a college to write a Java program to use a so-called check sum technique for catching typing errors of student ID. The college assigns a seven-digit number to each student. The seventh digit (i.e., the rightmost digit) is determined from the other digits with the use of the following formula: 7th digit = (1 *(1st digit) * 2 * (2nd digit) * ... * 6 * (6th digit)) % 10 Your program should prompt users to...
Looking for some help with this Java program I am totally lost on how to go about this. You have been approached by a local grocery store to write a program that will track the progress of their sales people (SalesPerson.java) The information needed are: D Number integer Month 1 Sales Amount-Double Month 2 Sales Amount-Double Month 3 Sales Amount-Double Write a Java program that allows you to store the information of any salesperson up to 20 While the user...