Question

In: Computer Science

IN JAVA Write a program that calculates the occupancy rate for each floor of a hotel....

IN JAVA

Write a program that calculates the occupancy rate for each floor of a hotel. (Use a sentinel value and please point out the sentinel in bold.) The program should start by asking for the number of floors in the hotel. A loop should then iterate once for each floor. During each iteration, the loop should ask the user for the number of rooms on the floor and the number of them that are occupied. After all the iterations, the program should display the number of rooms the hotel has, the number of them that are occupied, the number that are vacant, and the occupancy rate for the hotel. Input Validation: Do not accept a value less than 1 for the number of floors. Do not accept a number less than 10 for the number of rooms on a floor.

SAMPLE OUTPUT:

Enter number of floors:
2
Enter total rooms at floor 1:
10
Enter total rooms occupied at floor1:
5
Enter total rooms at floor 2:
10
Enter total rooms occupied at floor2:
5
Total rooms: 20
Total occupied rooms: 20
Hotel occupany: 50.0

Solutions

Expert Solution

Solution to the Problem Given in JAVA -

import java.util.Scanner;

import java.text.*;

public class HotelOccupancy {

               

                public static void main(String[] args) {

                int floors;

                double rooms = 0;

                int roomsOccupied = 0;

                double totalRms = 0;

                double totalRmsOccupied = 0;

                double totalVacant = 0;

                double occupancyRate = 0.0;

                               

// Create Scanner object for input

                           Scanner input = new Scanner(System.in);

                               

                                // Ask User to Enter to Enter floor count

                                System.out.print("Enter the number of floors: ");

                                floors = input.nextInt();

                               

                                // Input validation Floor count must be > 0

                                while(floors < 1){

                          System.out.print("Invalid Input. Please enter a number of floors greater than 0: ");

            floors = input.nextInt();

                                }

                               

                               

                                for(int i=0; i<floors; i++){

                                                // Ask user for the number of rooms on a floor

                                                System.out.print("Enter total rooms at floor (Floor " + (int)(i + 1) + "): ");

                                                rooms = input.nextInt();

                                               

                                                // Validation of Room Entered by the user

                                                while(rooms < 10){

                 System.out.print("Incorrect input. Please a number of rooms greater than 9 \n(Floor " + (int)(i + 1) + "): ");

                                       rooms = input.nextInt();

                                                }

                                               

                                                // Prompt user for the number of rooms occupied.

                 System.out.print("Enter total rooms occupied at floor (Floor " + (int)(i + 1) + "): ");

                roomsOccupied = input.nextInt();

                                               

                                                // Calculate total rooms

                                                totalRms += rooms;

                                               

                                                // Calculate total rooms occupied

                                                totalRmsOccupied += roomsOccupied;

                                }

                               

             // Calculate total vacancy available

                                totalVacant = totalRms - totalRmsOccupied;

                               

                                // Calculate occupancy rate

                                occupancyRate = (totalRmsOccupied/totalRms);

                               

                                // Decimal formating

                                NumberFormat df = DecimalFormat.getInstance();

                                df.setMaximumFractionDigits(2);

                               

                               // Display Hotel Occupancy data

System.out.println("Total Rooms: " + totalRms + "\nOccupied(QTY): " + totalRmsOccupied +

"\nVacant Rooms(QTY): " + totalVacant + "\nOccupancy Rate: " + df.format(occupancyRate) + "%");

                }

}


Related Solutions

IN JAVA Write a program that calculates the occupancy rate for each floor of a hotel....
IN JAVA Write a program that calculates the occupancy rate for each floor of a hotel. (Use a sentinel value and please point out the sentinel in bold.) The program should start by asking for the number of floors in the hotel. A loop should then iterate once for each floor. During each iteration, the loop should ask the user for the number of rooms on the floor and the number of them that are occupied. After all the iterations,...
Write a program that calculates the occupancy rate for each floor of a hotel. (Use a...
Write a program that calculates the occupancy rate for each floor of a hotel. (Use a sentinel value and please point out the sentinel in bold.) The program should start by asking for the number of floors in the hotel. A loop should then iterate once for each floor. During each iteration, the loop should ask the user for the number of rooms on the floor and the number of them that are occupied. After all the iterations, the program...
Hotel Occupancy C++ Only Program Description Write a program that calculates the occupancy rate for a...
Hotel Occupancy C++ Only Program Description Write a program that calculates the occupancy rate for a hotel. The program should read its data from a file named "hotel.dat". The first line of this file will be a single integer specifying the number of floors in the hotel. Each of the remaining (N) lines will have two integers; the number of rooms on that floor and the number of occupied rooms on that floor. Your program should display the following: How...
Using Loops for the Hotel Occupancy calculator. You will write a program that calculates the occupancy...
Using Loops for the Hotel Occupancy calculator. You will write a program that calculates the occupancy of a hotel. Rules: 1# The hotel must have more than 2 floors and less than or equal 5 floors. 2# Each floor in the hotel can have a different number of rooms on the floor. 3# You must set the number of occupied rooms. Again, there must less rooms occupied than the number of rooms. 4# Using the total number of rooms and...
Write a program that calculates the occupancy rate for a hotel. The program should start by asking the user how many floors the hotel has.
Use JAVAProgram #1: Hotel Occupancy: Write a program that calculates the occupancy rate for a hotel. The program should start by asking the user how many floors the hotel has. A for loop should then iterate once for each floor. In each iteration of the for loop, the program should ask the user for the number of rooms of the floor and how many of them are occupied. After all of the iterations are complete the program should display how...
I need to make an application that calculates the occupancy rate for a hotel with eight...
I need to make an application that calculates the occupancy rate for a hotel with eight floors. The user will be asked how many rooms are occupied on each floor. The program will iterate for each floor. Users must enter numbers and the rooms occupied on each floor cannot exceed 30. The occupancy rate is the number of occupied rooms/ unnoccupied.  The application also needs to display the occupancy for each individual floor aswell. Each floor has a maximum of 30...
Write a program that calculates the floor of a decimal number as defined here. Basically the...
Write a program that calculates the floor of a decimal number as defined here. Basically the Floor of any decimal number x, is the nearest whole number less than or equal to x. ( Code Should Be In C++) Requirements 1) You must implement a function to calculate the floor (you cannot use C++'s floor function). Name it floorAndError). It will have a return value and a single parameter 2) The program will ask the user to input a number...
Write a java program that calculates a speeding fine. The user is prompted for the speed...
Write a java program that calculates a speeding fine. The user is prompted for the speed of the vehicle, the posted speed limit and if the offence took place in the construction zone. The fine is calculated at $75 + 3$/ km over the speed limit for the first 20km over + $6 / km for the next 20 and $9/km after that. If the posted limit is 40km, the fine is doubled. If the offence took place in a...
Write a Java program that calculates a random number 1 through 100. The program then asks...
Write a Java program that calculates a random number 1 through 100. The program then asks the user to guess the number.If the user guesses too high or too low then the program should output "too high" or "too low" accordingly.The program must let the user continue to guess until the user correctly guesses the number. ★Modify the program to output how many guesses it took the user to correctly guess the right number
Following are the number of victories for the Blue Sox and the hotel occupancy rate for...
Following are the number of victories for the Blue Sox and the hotel occupancy rate for the past eight years. You have been asked to test three forecasting methods to see which method provides a better forecast for the Number of Blue Sox Wins. Year Number of Blue Sox Wins Occupancy Rate 1 70 78% 2 67 83 3 75 86 4 87 85 5 87 89 6 91 92 7 89 91 8 85 94 For the following, you...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT