Question: 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
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.
Hotel.java
public class Hotel extends Building { private String hotelName, pentHouseMembers; private Room pentHouseRoom; private 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. */ public Hotel(String hotelName, String address, int maxFloors, int roomsPerFloor, int roomCapacity, String pentHouseMembers, int pentHouseCapacity, boolean hasPool) { throw new UnsupportedOperationException("Implement this method"); }
/* * 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. */ @Override public boolean addOccupant(String name, int floorIndex, int roomNumberIndex) { throw new UnsupportedOperationException("Implement this method"); }
/* * 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. */ public ArrayList
/* * Get method for hasPool. */ public boolean hotelHasPool() { throw new UnsupportedOperationException("Implement this method"); }
/* Does not include penthouse; if two have the same value the lower level one * 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. */ public int[] getFloorMaxOccupants() { throw new UnsupportedOperationException("Implement this method"); }
/* * 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. */ public static int totalNumberHotelsWithPool(ArrayList
/* 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; } }
StudentTest.java
public class StudentTests { @Test public void test() { fail("Not yet implemented"); } }
SampleDriverHotel.java
public class SampleDriverHotel {
public static void main(String[] args) { StringBuffer results = new StringBuffer();
String hotelName = "TerpHotel", address = "CollegePark"; int maxFloors = 2, roomsPerFloor = 2, roomCapacity = 4; int pentHouseCapacity = 10; String pentHouseMembers = "Smith"; boolean hasPool = true;
Hotel hotelOne = new Hotel(hotelName, address, maxFloors, roomsPerFloor, roomCapacity, pentHouseMembers, pentHouseCapacity, hasPool);
hotelOne.addOccupant("Swati", 0, 1); hotelOne.addOccupant("Anastasia", 0, 1); hotelOne.addOccupant("Olivia", 0, 1);
hotelOne.addOccupant("Liv", 1, 1); hotelOne.addOccupant("Phoebe", 1, 1);
results.append(hotelOne + " "); boolean pentHouse = false; ArrayList
System.out.println(results); } }
Output
Hotel: TerpHotel PentHouseMembers: Smith PentHouseRoom: Capacity: 10, Occupants: [] Pool: Yes Address: CollegePark MaxFloors: 2, RoomsPerFloor: 2, RoomCapacity:4
****** Floor: 0 ****** Room: 0, Capacity: 4, Occupants: [] Room: 1, Capacity: 4, Occupants: [Swati, Anastasia, Olivia]
****** Floor: 1 ****** Room: 0, Capacity: 4, Occupants: [] Room: 1, Capacity: 4, Occupants: [Liv, Phoebe]
[Anastasia, Olivia, Swati]
Thank you i will thumbs up you just need to do student test which check each method of hotel and hotel.java
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
