Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hotel class The Hotel class (see Hotel.java) represents a hotel and extends the Building class. The instance variables are provided below. A hotel is a

image text in transcribedimage text in transcribed

Hotel class

The Hotel class (see Hotel.java) represents a hotel and extends the Building class. The instance variables are provided below. A hotel is a building with floors and rooms per floor. In addition, a hotel has a special room called the penthouse, that only people with pentHouseMembers in their name can occupy. For example, if pentHouseMembers is Smith, anyone with Smith in their name (e.g., John Smith, Smith Mary, etc.) can occupy the penthouse. A hotel may or may not have a pool. We provided a toString() method for this class; do not modify it. private String hotelName, pentHouseMembers; private Room pentHouseRoom; private boolean hasPool; a. public Hotel(String hotelName, String address, int maxFloors, int roomsPerFloor, int roomCapacity, String pentHouseMembers, int pentHouseCapacity, boolean hasPool) - Initializes the instance variables with the corresponding parameter values. The constructor will call the super class constructor to initialize the building component of the hotel. Make sure you use roomCapacity to initialize the capacity of hotel rooms and pentHouseCapacity to initialize the penthouse capacity. b. public boolean addOccupant(String name, int floorIndex, int roomNumberIndex) - If name contains the pentHouseMembers string, the name will be added to the penthouse; otherwise it will be added to the room associated with the specified indices. The method will return true if the name was added as an occupant and false otherwise. You can use the String class contains method to verify whether name has the pentHouseMembers string. This method overrides a method. c. public ArrayList getOccupants(boolean pentHouse, int floorIndex, int roomIndex, boolean sorted) - Returns an ArrayList with the occupants of a room. If penthouse is true, ONLY the occupants of the penthouse will be returned. If penthouse if false, ONLY the occupants of the room associated with the specified indices will be returned. If the sorted parameter is true, the ArrayList will be sorted (using Collections.sort()) before it is returned. If the indices are invalid an empty ArrayList will be returned. d. public boolean hotelHasPool() - Get method for hasPool. e. public int[] getFloorMaxOccupants() - Returns an array with two integers (array of size 2). The first entry of the array is the index of the floor with the maximum number of occupants, and the second value is the maximum number of occupants on that floor. If two floors have the same maximum number of occupants, the first floor found (the one with the lowest index value) will be used. If the floors are empty, the returned array will have the values 0 and 0. This method does not look at the occupants in the penthouse room; it looks for the maximum number of occupants only on floors. f. public static int totalNumberHotelsWithPool(ArrayList buildings) - This static method has as parameter an ArrayList of Building references. Remember that not all buildings are hotels. The method will return the number of buildings that are hotels and that have a pool.

/* Provided: do not modify */ @Override public String toString() { String answer = "Hotel: " + hotelName + " ";

answer += "PentHouseMembers: " + pentHouseMembers + " "; answer += "PentHouseRoom: " + pentHouseRoom + " "; answer += "Pool: " + (hasPool ? "Yes" : "No") + " "; answer += super.toString();

return answer; }

Hotel class please, an upvote for exactly follow the instructions, thanks.

The Room class (see Room.java) represents a room in a building. The instance variables (see below) associated with this class are capacity (maximum number of occupants in a room) and occupants (names of persons that are in the room). You can assume names are unique. We provided a toString() method for this class; do not modify it. private int capacity; private ArrayList occupants; a. c. public Room(int capacity) - Initializes the capacity with the parameter value and creates an ArrayList of string references. b. public boolean addOccupant(String name) - Adds the specified name to the occupants ArrayList if the maximum capacity has not been reached. If the name is added the method returns true; if the maximum capacity has been reached, the method returns false (and no name is added). If the name already exists, the name is not added and the method will return false. The method will throw an IllegalArgumentException (with any error message) if the parameter is null or blank according to the String class method isBlank(). public int getCapacity0 - Get method for capacity. d. public Room(Room room) - Copy constructor. Changes to the copy should not affect the original. e. public ArrayList getOccupants() - Get method for occupants that returns a copy of the occupants ArrayList. f. public int getNumberOfOccupants0 - Returns the number of occupants (names added to the occupants ArrayList). g. public int compareTo(Room room) - The Room class implements the Comparable interface. The compareTo method will return a negative value if the number of occupants in the current object is less than the parameter, 0 if they are the same, and positive otherwise. h. public boolean equals(Object obj) - Implement the equals method where two rooms are considered the same if they have the same number of occupants and the same occupants. The occupants can appear in any order in the occupants ArrayLists. For example, if room1 added two occupants, Rose, Mike (in that order) and room2 added Mike, Rose (in that order), the rooms are considered equal. You can use any String class methods. The Building class (see Building.java) represents a building with several floors, where each floor has several rooms. The instance variables are provided below. The instance variable allFloors is a two-dimensional array (not a ragged array) of Room references. Each row of the array represents a building floor, where the first floor has index 0, the second index 1, etc. The maximum number of floors is represented by maxFloors. The roomsPerFloor instance variable represents the maximum number of rooms per floor, and roomCapacity the maximum capacity of each room. All the building rooms have the same capacity. We provided a toString() method for this class; do not modify it. protected Room[][] allFloors; protected int maxFloors, roomsPerFloor, roomCapacity; private final String address; a. public Building(String address, int maxFloors, int roomsPerFloor, int roomCapacity) - Initializes the instance variables with the corresponding parameter values. The allFloors instance variable will be initialized with a two-dimensional array of references to Room objects, where the number of rows corresponds to maxFloors and the number of columns to roomsPerFloor. Each entry of the array must be initialized to a Room object that has a capacity corresponding to the roomCapacity parameter. b. public Building0 - Initializes a building with the address "NOADDRESS" and defines a building that has 1 floor, 1 room and a maximum capacity of 1 for the room. c. protected Room getRoom(int floorIndex, int roomNumberIndex) - Returns the Room reference associated with the array entry with index values floorIndex and roomNumberIndex. If any of the index values is invalid (e.g., negative or larger than a valid value) the method will throw an IllegalArgumentException with any error message. d. public boolean addOccupant(String name, int floorIndex, int roomNumberIndex) - Adds the name as an occupant of the room associated with floorIndex and roomNumberIndex. The method will return true if the occupant was added and false otherwise (e.g. maximum capacity was reached). The method will also return false and not crash the program if the index values provided are invalid. You should rely on the getRoom method previously defined during the implementation of this method

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago