Answered step by step
Verified Expert Solution
Question
1 Approved Answer
public class Person{ //variables to store first and last names private String firstName; private String lastName; /** * * @param firstName person's first name *
public class Person{ //variables to store first and last names private String firstName; private String lastName; /** * * @param firstName person's first name * @param lastName person's last name */ //constructor with two parameters public Person(String firstName,String lastName){ this.firstName = firstName; this.lastName = lastName; } //overriding toString method public String toString(){ //returning first and last names seperated by space return firstName+" "+lastName; } }
public class Building{ // instance members of the class private int yearBuilt; private int floors; //default constructor public Building() { yearBuilt = 2021; floors = 1; } /** * * @param yearBuilt year the building was built * @param floors number of floors in the building */ // parameterized constructor that initialized // year built and floors public Building(int yearBuilt, int floors) { this.yearBuilt = yearBuilt; this.floors = floors; } }
package com.company; import java.sql.Date; class Reservation { private Date startDate, endDate; private double pricePerNight; private Person guest; private static int reservationNumber = 10001; /** * * @param startDate start date of the reservation * @param endDate end date of the reservation * @param pricePerNight cost per night * @param guest guest's name */ public Reservation(Date startDate, Date endDate, double pricePerNight, Person guest) { this.startDate = startDate; this.endDate = endDate; this.pricePerNight = pricePerNight; this.guest = guest; reservationNumber ++; } public Date getStartDate() { return startDate; } public Date getEndDate() { return endDate; } public int getReservationNumber() { return reservationNumber; } public boolean available(Date startDate, Date endDate) { return this.startDate.compareTo(startDate) = 0; } @Override public String toString() { return "Reservation Number: " + reservationNumber + ". From " + startDate + " To: " + endDate + ", Guest: " + guest + ", $" + pricePerNight + " per night."; } }
import java.sql.Date; import java.util.ArrayList; enum RoomType { SINGLE, DOUBLE, STUDIO, SUITE } class Room { private RoomType roomType; private double price; private double roomSize; private int floorNumber; private int roomNumber; private String description; private boolean isVacant; private ArrayListreservations; /** * * @param roomType type of the room * @param price price of the room * @param roomSize size of the room * @param floorNumber number of the floor * @param roomNumber number of the room * @param description description of the room */ public Room(RoomType roomType, double price, double roomSize, int floorNumber, int roomNumber, String description) { this.roomType = roomType; this.price = price; this.roomSize = roomSize; this.floorNumber = floorNumber; this.roomNumber = roomNumber; this.description = description; isVacant = true; reservations = new ArrayList(); } public double getPrice() { return price; } public int getRoomNumber() { return roomNumber; } public boolean getVacancyStatus() { return isVacant; } public ArrayList getReservations() { return reservations; } public void setPrice(double price) { this.price = price; } public int reserve(Date startDate, Date endDate, Person guest) { if (isVacant) { reservations.add(new Reservation(startDate, endDate, price, guest)); return roomNumber; } return 0; } public void cancel(int reservationNumber) { for (Reservation reservation : reservations) { if (reservation.getReservationNumber() == reservationNumber) { reservations.remove(reservationNumber); } } } public String status() { StringBuilder sb = new StringBuilder(); sb.append("Reservation list of room number: ").append(roomNumber).append(": "); if (isVacant) { sb.append("Vacant."); } else { sb.append("Not Vacant."); } for (Reservation reservation : reservations) { sb.append(" ").append(reservation); } return sb.toString(); } @Override public String toString() { return roomType + ", price=$" + price + ", Size=" + roomSize + ", Number=" + roomNumber + ", Floor=" + floorNumber + ", " + description; } }
Class Hotel (30 marks): Open the Java file Hotel.java that is provided. Note that every hotel is a building with some extra features. You must consider this fact in the implementation of the class Hotel. Complete this Java class using the following specifications: Every hotel has (4 marks) name rate one or more owners one or more rooms Provide the default constructor for the class, which only calls the default constructor of its superclass. (1 mark) Provide the second constructor for the class, with five parameters, hotel name, list of the hotel owners, year of built, number of floors, and hotel rate, which initializes the corresponding instance variables. Note that the proper constructor of the superclass must be called in this constructor. Also, the list of the hotel rooms must be initialized. (4 marks) Provide getter methods for hotel name and owners. (2 marks) Provide a getter method, getRooms, which returns the list of the hotel rooms as an ArrayList of rooms. (1 mark) Provide a getter method, getRoom, with one parameter, room number, which returns the corresponding room as its return type, and otherwise null. (1 mark) Provide a method, addowner, which adds one owner to the hotel's owners list. (1 mark) Provide a method, addRoom, which adds a new room to the hotel. (1 mark) Provide a method, reserve, with four parameters, room number, start date, end date, and guest. It will first find the room using one of the above methods. If it finds the room, then it simply calls the reserve method of that room, receives the reservation number and returns it. If the room is not found, it returns zero, which means the reservation was not successful. (4 marks) Provide a method, cancel, with one parameter, reservation number. It should find the room that has this reservation numbers. If it finds the room, then it will call the cancel method of that room with the reservation number given, and then returns true. Otherwise, it returns false, which means the cancellation was not successful. (3 marks) Override the tostring method, such that it returns a string including the hotel information, with the format like example below. It shows the hotel information, followed by the rooms' information. (3 marks) Hotel Baba Mama, 3.5 stars. Hotel Owners: Ali Baba Rooms : SINGLE, price=$35.5, Size-200.0, Number=101, Floor-1, Single Room without view DOUBLE, price-$50.5, Size-350.0, Number-102, Floor-1, Double Room without view DOUBLE, price-$55.0, Size-400.0, Number-201, Floor-2, Double Room with view SUITE, price=$80.0, Size=500.0, Number-202, Floor-2, Suite Room with view and balcony Alice Mama Provide standard Java Documentation for all the public methods as well as one brief explanation for the Hotel class at the top of the class. Note that your documentation must follow the correct syntax of Java Documentation and not just simple comments
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