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
Asked Mar 12, 2019
289 views
1. 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)
help_outline

Image Transcriptionclose

1. 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

Expert Answer

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;

//Read input for each floor
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

Check out a sample Q&A here.

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

Engineering

Computer Science

Programing Language

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: List the octal and hexadecimal numbers from 1410 to 3210. Using A and B for the last two digits, lis...

A: Answer:Listing octal values from 1410 to 3210:Divide 14 by 8 (octal number) giving 1 remainder 61 is...

question_answer

Q: Develop the ‘Shape’ application such that: Implement an array of objects of various types (all SIX ...

A: Program plan:Define a class called “ShapeTest”.Define a “main()” method.Create an array of six shape...

question_answer

Q: Write a program called Convert, which converts an ASCII code to its equivalentcharacter. 1) Create a...

A: Java codeimport java.util.Scanner; public class Convert{public static void main(String[] args) {Scan...

question_answer

Q: How can I check if a binary number is an even number. So, the binary has a 0 remainder when divided ...

A: Approach: Result = (((n &gt;&gt; 1) &lt;&lt; 1) == n). First we shift the 1 bit right then we shift ...

question_answer

Q: I was asked to add the three types of comments to this class, each consisting of the same statement ...

A: Java documentation comment: This comment is used to create documentation API. The syntax for this co...

question_answer

Q: Find a pda that accepts the language L={anb2n :n≥0}.L={anb2n :n≥0}.

A: Pushdown Automata (PDA):In PDA, we can store one alphabet of language because PDA has only one stack...

question_answer

Q: Analyze the following code: Code 1: int number = 45;boolean even; if (number % 2 == 0) even = true;e...

A: First lets discuss about the first question. 1) In the first code we are declaring two variables num...

question_answer

Q: How would I write a C program to find the length of the longest substring of a given string without ...

A: The given program is to find the maximum length of the substring without repeating character. This i...

question_answer

Q: Attached Files:  sample.txt (11.069 KB) You will only get one submission. I need a python prog...

A: Three counters are used to keep track of the running count of the words being read from the supplied...