Question
I don't know how to call the ArrayList & ArrayList hotels from the main in TODO 10 & 11 Basically need help with TODO 10
I don't know how to call the ArrayList
Basically need help with TODO 10 & TODO 11
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
This is the main File (Project3_Client.java)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// import java.util.ArrayList; import java.util.Scanner;
public class CS125_Project3_Client { public static void main(String[] args) {
// Create scanner Scanner scan = new Scanner(System.in);
// Perform initial reading of data ArrayList
// 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 <= 0 || month > 12) System.out.println("Invalid month choice. Please try again..."); else if (checkinDay <= 0 || checkoutDay <= 0) System.out.println("Invalid check-in or check-out choice; must be greater than 0. 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 <= checkinDay) System.out.println("Invalid check-in or check-out range; cannot checkout before checking in. Please try again..."); else { invalidDateRange = false; }
} 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.");
}
---------------------------------------------------------------------------
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.text.DecimalFormat;
import java.util.ArrayList;
public class Hotel {
/////////////////////////////////////////////////////////////////////////////////////////
// Instance Variables
/////////////////////////////////////////////////////////////////////////////////////////
private long uniqueId;
private String hotelName;
private String address;
private String city;
private String stateAbb;
private double dollars;
/////////////////////////////////////////////////////////////////////////////////////////
// Overloaded Constructor
/////////////////////////////////////////////////////////////////////////////////////////
public Hotel(long id, String name, String addr, String cityName, String stAbbrev, double price) {
uniqueId = id;
hotelName = name;
address = addr;
city = cityName;
stateAbb = stAbbrev;
dollars = price;
}
/////////////////////////////////////////////////////////////////////////////////////////
// Default constructor
/////////////////////////////////////////////////////////////////////////////////////////
public Hotel() {
uniqueId = 0;
hotelName = "Hotel";
address = "Address";
city = "City";
stateAbb = "CA";
dollars = 0.00;
}
// Class Methods
/////////////////////////////////////////////////////////////////////////////////////////
// This method takes in a new reservation and compares it against
// all other reservations in this hotels reservations ArrayList.
// Returns true if the new reservation can be made; returns false
// if the new reserveration (newRes) will conflict with an old
// reservation.
/////////////////////////////////////////////////////////////////////////////////////////
public boolean canBook(Reservation newRes) {
// TODO 10: Add code to complete method...
}
/////////////////////////////////////////////////////////////////////////////////////////
// Adds the new reservation (newRes) to the ArrayList of reservations
// (instance variables)
public void addReservation(Reservation newRes) {
// TODO 11: Add code to complete method...
}
Step 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