Question
/* CS 125 - Intro to Computer Science II * File Name: CS125_Project3_Client.java * Project 3 - Due X/XX/XXXX * Instructor: Dr. Dan Grissom *
/* CS 125 - Intro to Computer Science II * File Name: CS125_Project3_Client.java * Project 3 - Due X/XX/XXXX * Instructor: Dr. Dan Grissom * * Name: FirstName LastName * Description: Insert your meaningful description for Project 3. */
import java.io.EOFException; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.Scanner;
public class CS125_Project3_Client { public static void main(String[] args) { // Your program should always output your name and the lab/problem // number. DO NOT DELETE OR COMMENT OUT. Replace with relevant info. // TODO 15: Update your name... System.out.println("Name"); System.out.println("Project 3"); System.out.println("");
// Create scanner Scanner scan = new Scanner(System.in);
// Perform initial reading of data ArrayList hotels = getHotelsFromFile("Hotels.txt"); ArrayList reservations = readReservationsFromFile("Reservations.txt");
// Associate each reservation with the appropriate hotel assignReservationsToCorrectHotel(reservations, hotels);
// Print out welcome System.out.println("Welcome to the Parental Paradise Hotel Chain."); Hotel selectedHotel = null;
// Prompt with hotel list and repeat until get valid hotel selection do { System.out.println("Please select from one of the following hotels (select the number and press enter) to make a reservation: "); for (Hotel h : hotels) System.out.println("\t" + h.toDisplayString()); System.out.print(" Your selection: ");
// Read user input & get hotel int choice = scan.nextInt();
for (Hotel h : hotels) if (h.getUniqueId() == choice) selectedHotel = h;
if (selectedHotel == null) System.out.println("Invalid hotel choice. Please try again...");
} while (selectedHotel == null);
// Create variables for reservation int month; int checkinDay; int checkoutDay; boolean invalidDateRange = true;
// Prompt for check-in month and check-in/check-out day until get valid selection do { System.out.println("Please enter details about your reservation request: "); System.out.print("\tMonth (1-12): "); month = scan.nextInt(); System.out.print("\tCheck-in day: "); checkinDay = scan.nextInt(); System.out.print("\tCheck-out day: "); checkoutDay = scan.nextInt();
if (month 12) System.out.println("Invalid month choice. Please try again..."); else if (checkinDay 31 || checkoutDay > 31) System.out.println("Invalid check-in or check-out choice; must be greater than 0. Please try again..."); else if (checkoutDay == checkinDay) System.out.println("Invalid check-in or check-out range; must stay at least one night. Please try again..."); else if (checkoutDay
} while (invalidDateRange);
// Create reservation from user input Reservation newRes = new Reservation(selectedHotel.getUniqueId(), month, month, checkinDay, checkoutDay); // Try to add reservation if (selectedHotel.addResIfCanBook(newRes)) { // Then add new reservation to global reservations list and write out to file System.out.println("Reservation successfully added: " + selectedHotel.getHotelName() + ": " + newRes.getFormattedDisplayString(selectedHotel.getPricePerNight())); reservations.add(newRes); writeReservationFile("Reservations.txt", reservations); } else { System.out.println("Could not add the reservation (" + newRes.getFormattedDisplayString() + ") to " + selectedHotel.getHotelName() + " b/c of a conflict."); System.out.println("Please re-run the program to try a new date."); } // Exit program System.out.println(" Thank you for using the Parental Paradise Hotel Manager.");
}
////////////////////////////////////////////////////////////////////////////////////////////////////// // This method takes in a list of hotels and reservations. At this point, the hotel // objects should have an empty ArrayList of Reservations (as an instance variable). // This method cycles through the reservations and assigns them to the hotel with // matching uniqueId as the resrevation's hotelId. ////////////////////////////////////////////////////////////////////////////////////////////////////// private static void assignReservationsToCorrectHotel(ArrayList reservations, ArrayList hotels) { // TODO 16: Add code to complete method... }
////////////////////////////////////////////////////////////////////////////////////////////////////// // Reads Hotels from fileName and returns as a new ArrayList of hotels. // // Uses plain-text input. ////////////////////////////////////////////////////////////////////////////////////////////////////// private static ArrayList getHotelsFromFile(String fileName) { // TODO 17: Add code to complete method... }
////////////////////////////////////////////////////////////////////////////////////////////////////// // Reads Reservations from a given file and stores them into the reservations // list. Returns a new ArrayList of reservations read in from file. If no reservations // in file found at fileName, should return an empty ArrayList. // // Uses serialize for input. ////////////////////////////////////////////////////////////////////////////////////////////////////// private static ArrayList readReservationsFromFile(String fileName) { // TODO 18: Add code to complete method... }
////////////////////////////////////////////////////////////////////////////////////////////////////// // Overwrites the file at fileName with the reservations found in globalReservations. // globalReservations should contain the reservations found in the file when the program // begin, as well as any new reservation the user made. Returns true upon success; false upon failure // // Uses serialize for input. ////////////////////////////////////////////////////////////////////////////////////////////////////// private static boolean writeReservationFile(String fileName, ArrayList globalReservations) { // TODO 19: Add code to complete method... } }
Requirements 1. Your program must first read from the included Hotels.txt file. It contains a number of lines of data; each line corresponds to a hotel in your chain (you may add more if you'd like and your code should not break). Each line is formatted as follows: Hotel(uniqueld, hotelName, streetAddress, city, stateAbbreviation, pricePerNight) You will need to create a simple Hotel class to encapsulate this data (template provided). 2. Your program must ask the user which hotel they'd like to stay in by listing all the hotels (with prices, address, etc.) with a number to the side, and then prompting the user to select a hotel by entering the corresponding number (corresponding to the unique ID). Once they've selected a hotel, you need to prompt the user for check-in month/day and check-out month/day. If they enter two different months, inform them that hotel policy does not allow them to check out during a different month (we have some interesting rules) and ask them to try again until they enter a valid range. Once they enter a valid range, according to the last paragraph, you must check all previously made reservations (which you will be storing in a file). If there is no conflicting reservation, inform the user that their reservation was successful and tell them how much they will owe for their entire stay (don't worry about tax). If there is a conflict with a previous booking, then inform the user and allow them to try different dates. The included runnable jar file will demonstrate exact syntax (all months and days will be entered as integers) and flow (template provides most of syntax/flow for you). 3. When you make a reservation, you must store it in a separate file (call it Reservations.txt) such that it can be referenced when the program is opened to make a reservation with a new customer later. Create a Reservation class to encapsulate this concept. To associate a particular reservation (which basically consists of the check-in month/day, check-out month/day) with a particular hotel, you will also need to store a hotel id (same thing as the hotel's uniqueld) in the Reservation which directly corresponds to one of the hotel unique ids. You must use serialization techniques to save the reservations to a file. HINT: You should create a Reservation class (template file provided), which encapsulates the above idea. You could then add an ArrayList of Reservations to your Hotel class. After you read in and create your hotel objects, you'd read in the reservations from file and add them to the hotel's reservation ArrayList (i.e., it would be a good idea for the Hotel class to have an "ArrayListStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started