The ElGrande Hotel has eight floors and 30 rooms on each floor. Create an applic
ID: 673869 • Letter: T
Question
The ElGrande Hotel has eight floors and 30 rooms on each floor. Create an application that calculates the occupancy rate for each floor, and the overall occupancy rate for the hotel. The occupancy rate is the percentage of rooms occupied, and may be calculated by dividing the number of rooms occupied by the number of rooms. For examiple, if I 8 rooms onthe first floor are occupied, the occupancy rate is as follows: 18/30-6 or 60% The application's form should appear similar to the one shown. When the user clicks the Complete Report button, a loop should execute and iterate eight times. Each time the loop iterates, it should display an input box for one of the hotel's floors. The input box should ask the user to enter the number of rooms occupied on that floor. As the user enters a value for each floor, the loop should calculate the occupancy rate for that floor, and display the information for that floor in the list box. When the number of occupied rooms has been entered for all the floors, the application should display the total number of rooms occupied and the overall occupancy rate for the hotel. (The hotel has a total of 240 rooms.) The following figure shows an example of the form after occupancy information has been provided for all the floors. The Clear button should clear all the appropriate controls on the form. The Exit button should end the application. Be sure to add appropriate ToolTips for the button Controls. Input validation: Do not accept a number less than 0 or greater than 30 for the number of occupied rooms on each floor.Explanation / Answer
public class HotelOccupancy
{
public static void main(String[] args)
{
int floors;
double rooms = 0;
int roomsOccupied = 0;
double totalRooms = 0;
double totalRoomsOccupied = 0;
double totalVacancy = 0;
double occupancyRate = 0.0;
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of floors: ");
floors = input.nextInt();
while(floors < 1)
{
System.out.print("Invalid Input. Enter a number of floors greater than 0: ");
floors = input.nextInt();
}
for(int i=0; i<floors; i++)
{
System.out.print("Enter the number of rooms (Floor " + (int)(i + 1) + "): ");
rooms = input.nextInt();
while(rooms < 10)
{
System.out.print("Invalid input. Enter a number of rooms greater than 9 (Floor " + (int)(i + 1) + "): ");
rooms = input.nextInt();
}
System.out.print("Enter the number of rooms occupied(Floor " + (int)(i + 1) + "): ");
roomsOccupied = input.nextInt();
totalRooms += rooms;
totalRoomsOccupied += roomsOccupied;
}
totalVacancy = totalRooms - totalRoomsOccupied;
occupancyRate = (totalRoomsOccupied/totalRooms);
NumberFormat df = DecimalFormat.getInstance();
df.setMaximumFractionDigits(2);
System.out.println("Total Rooms: " + totalRooms + " Occupied(QTY): " + totalRoomsOccupied + " Vacant Rooms(QTY): " + totalVacancy + " Occupancy Rate: " + df.format(occupancyRate) + "%");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.