# 1. Write a complete Java program that prompts userfor the number of floors in a hotel. Validate thefloors input: Do not accept a value less than 1 forthe number of floors. A loop should then iterateonce for each floor. During each iteration, theloop prompts user for(a) The number of rooms on the floor. Validatethe rooms input: Do not accept a value lessthan 10.(b) The number of rooms that are occupiedValidate the occupied rooms input: Do notaccept a value greater than the number ofrooms on the floor.(c) Calculate the number of vacant rooms oineach floor.(d) Calculate the occupancy rate on each floorOccupancy rate - 100 * rooms occupied / rooms onfloor(e) Calculate total number of rooms the hotel has(f) Calculate total number of occupied rooms thehotel has(g) Calculate total number of vacant rooms in thehotel(h) Calculate the occupancy rate for the hotelHotel Occupancy Rate - 100 * totalOccupiedRooms/ totalRoomsInHotelOutput:1.2.3,4.5.6.Rooms on each floorOccupied rooms on each floorVacant rooms on each floorOccupancy rate for each floorTotal number of rooms the hotel hasTotal number of occupied rooms the hotelhasTotal number of vacant rooms the hotel hasOccupancy rate for the hotel7.8.Submit:1. An algorithm2. A complete Java Program (include comments inyour program)3. Output (see above)

Question
289 views help_outlineImage Transcriptionclose1. Write a complete Java program that prompts user for the number of floors in a hotel. Validate the floors input: Do not accept a value less than 1 for the number of floors. A loop should then iterate once for each floor. During each iteration, the loop prompts user for (a) The number of rooms on the floor. Validate the rooms input: Do not accept a value less than 10. (b) The number of rooms that are occupied Validate the occupied rooms input: Do not accept a value greater than the number of rooms on the floor. (c) Calculate the number of vacant rooms oin each floor. (d) Calculate the occupancy rate on each floor Occupancy rate - 100 * rooms occupied / rooms on floor (e) Calculate total number of rooms the hotel has (f) Calculate total number of occupied rooms the hotel has (g) Calculate total number of vacant rooms in the hotel (h) Calculate the occupancy rate for the hotel Hotel Occupancy Rate - 100 * totalOccupiedRooms / totalRoomsInHotel Output: 1. 2. 3, 4. 5. 6. Rooms on each floor Occupied rooms on each floor Vacant rooms on each floor Occupancy rate for each floor Total number of rooms the hotel has Total number of occupied rooms the hotel has Total number of vacant rooms the hotel has Occupancy rate for the hotel 7. 8. Submit: 1. An algorithm 2. A complete Java Program (include comments in your program) 3. Output (see above) fullscreen
check_circle

Step 1

Note: The given java program has been compiled and executed in "repl.it" online complier.

Step 2

1. Algorithm:

Step 1: Start.

Step 2: Define main class.

Step 3: Define main function.

Step 4: Declare variable “totalFloor”.

Step 5: Create the scanner object “sc” using “Scanner” class.

Step 6: Display the given message “Enter number of floors in a hotel:”

Step 7: Validate the floors input by using “Do-While” loop.

Do

Read the number of floors on the hotel from user.

If totalFloor < 1

Display the message “Invalid input. Number of floors should be atleat 1”

Display the message “Enter the number of floors in a hotel:”

While totalFloor < 1

Step 8: Declare and initializes required variable

Set “totalRoomsInHotel” to “0”.

Set “totalOccupiedRooms” to “0”

Step 9: Loop iteration for each floor

Declare variables “roomOnFloor”, “roomOccupied” and “vacantRooms”.

Read input for number of rooms on each floor.

Display the given message “Enter the number of rooms on the floor:”

Validate number of rooms on each floor using “Do-While” loop

Do that is repeat the steps until “roomOnFloor < 10”

Read the number of rooms on each floor from user.

If roomOnFloor < 10, Then

Display the message “Invalid input. Number of rooms on the floor should be atleast 10:”

Display the message “Enter the number of rooms on the floor:”

While roomOnFloor < 10

Compute the total rooms in hotel.

Set totalRoomsInHotel = totalRoomsInHotel + roomOnFloor

Display given message “Enter the number of rooms that are occupied on that floor:”

Validate occupied rooms on each floor using “Do-While” loop.

Do that is repeat the steps until “roomOccupied > roomOnFloor”

Read the number of occupied rooms on each floor from user.

If roomOccupied > roomOnFloor

Display given message “Invalid input. Occupancy value cannot be greater than total rooms on floor:”

vacantRooms = roomOnFloor - roomOccupied

While roomOccupied > roomOnFloor

Compute occupancy rate for each floor.

Set occupancyRate = 100 * roomOccupied/roomOnFloor

Display the number of rooms on each floor.

Display the occupied rooms on each floor.

Display the vacant rooms on each floor.

Display the occupancy rate for each floor.

Step 10: Compute the total occupancy rate for the hotel.

Set totalOccupancyRate = 100 * totalOccupiedRooms/totalRoomsInHotel

Step 11:

Display the total number of rooms on the hotel.

Display the total number of occupied rooms on the hotel.

Display the total number of vacant rooms on the hotel.

Display the total occupancy rate.

Step 3

2. Complete Java Program:

//Import package for Scanner
import java.util.Scanner;
//Import package for DecimalFormat
import java.text.DecimalFormat;
//Define Main class
public class Main
{
//Define main function
publicstaticvoid main(String[] args)
{
//Declare variable
int totalFloor;

//Create scanner object
Scanner sc = new Scanner(System.in);

//Create decimal format object decimal point
DecimalFormat d = new DecimalFormat("#.##");

//Display the given message
System.out.println("Enter number of floors in a hotel: ");

//Validate the floor input
do
{
//Read the floor input from user
totalFloor = sc.nextInt();
//check floor condition
if(totalFloor < 1)
{
//Display message
System.out.println("Invalid input. Number of floors should be atleat 1");
System.out.println("Enter the number of floors in a hotel: ");
}
}
while(totalFloor < 1);
//Declare and initialized the required variable
int totalRoomsInHotel = 0;
int totalOccupiedRooms = 0;

//Loop iteration
for(int i = 1; i <= totalFloor; i++)
{
//Declare required variable
int roomOnFloor,roomOccupied,vacantRooms;

System.out.println("Floor "+ i +" ");
System.out.println("Enter the number of rooms on the floor: ");
//Validate number of rooms on floor
do
{
//Read input for number of rooms on each floor
roomOnFloor = sc.nextInt();
if(roomOnFloor < 10)
{
//Display message
System.out.println("Invalid input. Number of rooms on the floor should be atleast 10: ");
System.out.println("Enter the number of rooms on the floor: ");
}
}while(roomOnFloor < 10);

//Compute total rooms in hotel
totalRoomsInHotel = totalRoomsInHotel + roomOnFloor;

//Read the number of rooms that are occupied on the given floor
System.out.println("Enter the number of rooms that are occupied on that floor: ");

//Validate room occupied condition
do
{
//Read the occupied room from user
roomOccupied = sc.nextInt();

//Check condition
if(roomOccupied > roomOnFloor)
{
//Display the given message
System.out.println("Invalid input. Occupancy value cannot be greater than total rooms on floor: ");
}
//Compute the vacant rooms on each floor
vacantRooms = roomOnFloor - roomOccupied;
}while(roomOccupied > roomOnFloor);

//Compute the occu...

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

### Programing Language 