Please do this following program in the c language: Create a hotel reservation p
ID: 645786 • Letter: P
Question
Please do this following program in the c language:
Create a hotel reservation program with the following parameters:
The hotel has 20, 30, 40, or 50 rooms.
For each room you have to store the following information:
Room number. (assigned by program)
Room rate. (entered by user)
Smoking or non-smoking. (entered by user, max 8 per hotel)
Customer Id (if room is reserved). (entered by user)
Number of days reserved. (entered by user)
Prompt the user to enter the number of rooms in the hotel and create a two dimensional array (of variables type double) that fits the exact number entered. If the user enters a number other than 20, 30, 40, or 50, display an invalid input message and re-prompt the user to enter the right number.
Populate the room numbers as follows: the first 10 rooms numbered from 101 to 110, the second ten rooms numbered 201 to 210, and so forth. Use a function, roomNum, to assign the room numbers using loops. Initialize all other array locations to zero.
Display a menu asking the user for the following options:
A to add reservation.
C to cancel reservation.
R to retrieve reservation.
T to display all reservations.
X to exit program.
Adding reservation should be done with a function named addReservation. The user is asked first whether this will be smoking or nonsmoking and the availability of room is determined before adding the room (there are eight smoking rooms in any hotel, they could be any rooms, but a total of eight). If the room is available (not reserved), then the user is prompted to enter the rest of the reservation info, otherwise, display a message saying all rooms are reserved.
Cancel reservation will ask for the customer Id and free the rooms reserved by the customer (hint, a customer could reserve more than one room). This option is performed by a function named cancelReservation.
Retrieve reservation will ask for a customer Id and retrieve all the information for the rooms reserved by the customer, including the total cost of the hotel stay for the specific customer (tax is 12%). This option is performed by a function named retrieveReservation.
Display all reservations will display the information for all reservations by room number, and the total amount charged for all reservations, tax included. This option is performed by a function named displayAll.
Since the reservations could be cancelled, it is assumed that the array will not be uniformly filled. The addReservation function should add new reservations in the first available room in the array, for which the customer id would be zero.
Cancelling a reservation is done by setting all the fields except the room number to zero.
To indicate that a room is smoking, enter 1 for smoking, 0 for non-smoking.
Only function calls are allowed to execute menu options.
Array arguments passed to functions could be done with or without pointers, it is up to the programmer.
Explanation / Answer
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
public class Customer extends User {
public Customer() {
}
public void reserve() {
}
public void cancel() {
}
public void askQuestions(Scanner sc, ArrayList<Hotel> hotels,
ArrayList<String> (resInfo)
{
double price;
price = 0;
int choice = 0;
String string = null;
while (true) {
System.out.println("Thanks for choosing L4 Hotels. Would you like to make 1) a reservation or 2) cancel an existing booking ?");
choice = sc.nextInt();
switch (choice) {
case 1:
System.out.println("Which hotel type would you like: 1) 5*, 2) 4* or 3) 3*");
int hotelChoice;
while(true)
{
try {
hotelChoice = sc.nextInt();
break;
} catch (Exception e){
System.out.println("Please enter a valid token");
continue;
}
}
System.out.println("Here is your choice of rooms for hotel type chosen. Which room would you like ? ");
for (int i = 0; i < hotels.get(hotelChoice - 1).getRoomList().size(); i++) {
System.out.println(i+ 1+ ")"+ hotels.get(hotelChoice - 1).getRoomList().get(i).getType() + " ");
}
int roomChoice = sc.nextInt();
hotels.get(hotelChoice - 1).getRoomList().get(roomChoice - 1).setNum(hotels.get(hotelChoice - 1).getRoomList().get(roomChoice - 1).getNum() - 1);
String roomType = hotels.get(hotelChoice - 1).getRoomList().get(roomChoice - 1).getType();
while (true) {
System.out.println("How many adults will be staying. ?");
int adults = sc.nextInt();
if (adults > hotels.get(hotelChoice - 1).getRoomList().get(roomChoice - 1).getMaxAdults()) {
System.out.println("Currently the max Adult occupancy for this room is "+ hotels.get(hotelChoice - 1).getRoomList().get(roomChoice - 1).getMaxAdults());
continue; // brings you back to the start of the loop
}
hotels.get(hotelChoice - 1).getRoomList().get(roomChoice - 1).setCurrentAdults(adults);
break;
}
while (true) {
System.out.println("How many children will be staying. ?");
int children = sc.nextInt();
if (children > hotels.get(hotelChoice - 1).getRoomList().get(roomChoice - 1).getMaxChildren()) {
System.out.println("Currently the max child occupancy for this room is "+ hotels.get(hotelChoice - 1).getRoomList().get(roomChoice - 1).getMaxChildren());
continue;
}
hotels.get(hotelChoice - 1).getRoomList().get(roomChoice - 1).setCurrentChildren(children);
break;
}
System.out.println("Please enter your forename name please !");
String name = sc.next(); // verify later
hotels.get(hotelChoice - 1).getRoomList().get(roomChoice - 1).setName(name);
System.out.println("Please enter your contact number " + name);
int number = sc.nextInt();
hotels.get(hotelChoice - 1).getRoomList().get(roomChoice - 1).setNum(number);
String roomInfo = roomType + "," + number;
resInfo.add(roomInfo);
System.out.println("Thanks, your number will be used as a reference for your current booking.");
System.out.println("How many nights do you plan to stay.?");
int nights = sc.nextInt();
hotels.get(hotelChoice - 1).getRoomList().get(roomChoice - 1).setNights(nights);
System.out.println("And finally, what day of the week will you be arriving.");
String arrives = sc.next();
int i = 0;
/*
* while(true){
*
* if(hotels.get(hotelChoice -1).getRoomList().get(roomChoice
* -1).getDays()[i].compareToIgnoreCase(arrives)==0) {
*
* price += hotels.get(hotelChoice
* -1).getRoomList().get(roomChoice -1).getRates()[i]; } else
* if(i== hotels.get(hotelChoice
* -1).getRoomList().get(roomChoice -1).getDays().length ){ i=0;
* } }
*/
System.out.println("The resevation has been made. Due to a billing malfunction we cannot at this moment proccess the bill. You may pay on checkout :-D");
System.out.println(" Admin note: Successful reservations have been written to, and are viewable in resInfo.csv");
System.out.println(" End of session, program will terminate now :-) ");
break;
case 2:
while (true) {
System.out.println("Sorry to hear you will not be staying with us. Please enter your phone number which was used when you first booked with us to reference your reservation");
int phoneNum = sc.nextInt();
for (int j = 0; j < resInfo.size(); j++) {
String[] resInfoLine = new String[2];
resInfoLine = resInfo.get(j).split(",");
System.out.println(resInfoLine[0]);
if (phoneNum == Integer.parseInt(resInfoLine[1]))
{
for(int k=0; k<hotels.size(); k++){
for(int l=0; l<hotels.get(k).getRoomList().size(); l++){
if(hotels.get(k).getRoomList().get(l).getType().compareToIgnoreCase(resInfoLine[0])==0){
hotels.get(k).getRoomList().get(l).setNum(hotels.get(k).getRoomList().get(l).getNum() +1);
break;
}
}
}
}
if (j == resInfo.size()){
System.out.println("Sorry number wasnt found, Please re-enter.");
}
}
}
}
break;
}
}
}