class hotel holds information about each room in the hotelCo

class hotel holds information about each room in the hotel.Complete the Hotel definition by including the following

a. two instance variables: hotelName (String) and roomsList ( an array of Room Class)

b. a constructor that takes two input parameters that represent hotel name and the maximum number of rooms in the hotel. The constructor then uses the input parameters to initialize the instance variables.

c.getTotalCapacity() method that returns the total capacity of the hotel which is the sum of all rooms capacities. Assume that Rooms getters and setters are already implemented.

public class room{

private int roomNum;

private double rate;

private int capacity;

public room(int roomNum,double rate,int capacity){

Solution

hotel.java


public class hotel {
   private String hotelName ;
   private room roomsList[];
   public hotel(String name, int n){
       hotelName = name;
       roomsList = new room[n];
   }
   public String getHotelName() {
       return hotelName;
   }
   public void setHotelName(String hotelName) {
       this.hotelName = hotelName;
   }
   public room[] getRoomsList() {
       return roomsList;
   }
   public void setRoomsList(room[] roomsList) {
       this.roomsList = roomsList;
   }
   public int getTotalCapacity(){
       int total = 0;
       for(room r : roomsList){
           total = total + r.getCapacity();
       }
       return total;
   }
}

room.java


public class room{
   private int roomNum;
   private double rate;
   private int capacity;
   public room(int roomNum,double rate,int capacity){
       this.roomNum = roomNum;
       this.rate = rate;
       this.capacity = capacity;
   }
   public int getRoomNum() {
       return roomNum;
   }
   public void setRoomNum(int roomNum) {
       this.roomNum = roomNum;
   }
   public double getRate() {
       return rate;
   }
   public void setRate(double rate) {
       this.rate = rate;
   }
   public int getCapacity() {
       return capacity;
   }
   public void setCapacity(int capacity) {
       this.capacity = capacity;
   }
  
}

class hotel holds information about each room in the hotel.Complete the Hotel definition by including the following a. two instance variables: hotelName (String
class hotel holds information about each room in the hotel.Complete the Hotel definition by including the following a. two instance variables: hotelName (String

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site