I need to have Client.java , Hotel.java, Hotels.txt, Reservation.java, Reservati
ID: 3682490 • Letter: I
Question
I need to have Client.java , Hotel.java, Hotels.txt, Reservation.java, Reservation.txt .
Everything except Hotels.txt is blank. I need you to write the code from the scratch.
Hotels.txt contains these info:
Hotel(1, Azusa Inn, 23 Main St., Azusa, CA, 159)
Hotel(2, San Dimas Suits, 1456 Apollo Ave., San Dimas, CA, 129)
Hotel(3, Covina Comfort, 211 Crestline St., Covina, CA, 109)
Hotel(4, Hotel Glendorado, 394 W. Third St., Glendora, CA, 179)
Hotel(5, Pasadena Place, 483 Florence St., Pasadena, CA, 249)
Beyond the above requirements (using the given Hotel.txt file, user interface flow, serialized Reservations.txt requirements, etc.), you are free to complete this project however you’d like.
You plan to rent your hotel rooms out to anyone who is willing to pay the price. Although hotels typically have many rooms and you are flowing with cash, since you are new to the business, you have decided to start with a single penthouse suite at each hotel (only the best for your parents, of course). Thus, in this project, you will create a java application which acts as a hotel reservation system.Explanation / Answer
package com.dq.thematrix.main.java.test;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import org.eclipse.jetty.util.Scanner;
public class Hotel {
int uniqueId;
String hotelName;
String streetAddress;
String city;
String stateAbbreviation;
int pricePerNight;
public int getUniqueId() {
return uniqueId;
}
public void setUniqueId(int uniqueId) {
this.uniqueId = uniqueId;
}
public String getHotelName() {
return hotelName;
}
public void setHotelName(String hotelName) {
this.hotelName = hotelName;
}
public String getStreetAddress() {
return streetAddress;
}
public void setStreetAddress(String streetAddress) {
this.streetAddress = streetAddress;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getStateAbbreviation() {
return stateAbbreviation;
}
public void setStateAbbreviation(String stateAbbreviation) {
this.stateAbbreviation = stateAbbreviation;
}
public int getPricePerNight() {
return pricePerNight;
}
public void setPricePerNight(int pricePerNight) {
this.pricePerNight = pricePerNight;
}
}
class Reservation
{
String checkinMonth;
String checkoutMonth;
String checkoutDate;
String checkinDate;
public String getCheckinMonth() {
return checkinMonth;
}
public void setCheckinMonth(String checkinMonth) {
this.checkinMonth = checkinMonth;
}
public String getCheckoutMonth() {
return checkoutMonth;
}
public void setCheckoutMonth(String checkoutMonth) {
this.checkoutMonth = checkoutMonth;
}
public String getCheckoutDate() {
return checkoutDate;
}
public void setCheckoutDate(String checkoutDate) {
this.checkoutDate = checkoutDate;
}
public String getCheckinDate() {
return checkinDate;
}
public void setCheckinDate(String checkinDate) {
this.checkinDate = checkinDate;
}
}
class Client
{
public static void main(String args[])
{
System.out.println("Which Hotel would you like to stay in?");
System.out.println("Show your Menu here!");
//So here, we will read from Hotels.txt and display the name and address aside a number.
//I am showing an example
BufferedReader br = null;
try {
String sCurrentLine;
br = new BufferedReader(new FileReader("Hotels.txt"));
while ((sCurrentLine = br.readLine()) != null) {
System.out.println(sCurrentLine);
//HEre print only the name and address.
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
Scanner in = new Scanner(System.in);
System.out.println("Enter your choice");
String s = in.nextLine();
//On the basis of choice, use switch and case for the Hotel
System.out.println("Now Enter check in Details");
System.out.println("Enter check in Day");
String checkInDay=in.nextLine();
System.out.println("Enter check in Month");
String checkInMonth=in.nextLine();
System.out.println("Enter check out Day");
String checkoutDay=in.nextLine();
System.out.println("Enter check out Month");
String checkoutMonth=in.nextLine();
if(checkInMonth.equals(checkoutMonth))
System.out.println("Cannot allow to stay for such a long time. Sorry!");
else
{
Reservation R=new Reservation();
R.checkinDate=checkInDay;
R.checkinMonth=checkInMonth;
R.checkoutDate=checkoutDay;
R.checkoutMonth=checkoutMonth;
//Now write your data to file Reservations.txt
File file = new File("Reservations.txt");
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(R.toString());
bw.close();
}
}
}