Question

In: Computer Science

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 the total number of occupied rooms calculate the occupancy rate of the hotel. 5# Every input into this program must be checked to see if the numbers are valid.

JAVA

Solutions

Expert Solution

import java.util.Scanner;

public class HotelOccupancyCalc {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int floors;
       int totalRooms = 0;
       int totalOccupied = 0;
       double percentage;
       //reading floors
       while (true) {
           System.out.println("Enter number of floors: ");
           floors = sc.nextInt();
           //if it is valid floor break loop
           if (floors >= 2 && floors <= 5)
               break;
           // if it is invalid..keep asking for valid value
           System.out.println("Invalid input. try again..");
       }
       //reading total rooms and occupied rooms for each floor
       for (int i = 0; i < floors; i++) {
           System.out.println("Enter total rooms at floor " + (i + 1));
           totalRooms += sc.nextInt();
           System.out.println("Enter total occupied rooms at floor " + (i + 1));
           totalOccupied += sc.nextInt();
       }
       //finding percentage
       percentage = totalOccupied / (double) totalRooms;
       percentage = percentage * 100;
       System.out.println("Total rooms: "+totalRooms);
       System.out.println("Total occupied rooms: "+totalRooms);
       System.out.println("Hotel occupany : " + percentage + "%");
   }
}

Note : If you like my answer please rate and help me it is very Imp for me


Related Solutions

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...
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...
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 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...
Integer value calculator: Write a program using C++ that acts as a calculator. The program should...
Integer value calculator: Write a program using C++ that acts as a calculator. The program should ask the user for two numbers and an operator. Then the program must print the result using the two input values and the operator. Prompts and input requirements. Ask the user for two integer values and a value that indicates the operation. Likely you will want to choose the normal operators: + - * / %. Output Requirements: Make your output easy to understand,...
In this exercise we will practice using nested loops. You will write s program that prompts...
In this exercise we will practice using nested loops. You will write s program that prompts the user to enter an integer between 1 and 9 and displays a pyramid of numbers, as shown in the example below. The program must validate the input given by the user and make sure that: if the user enters a non-integer the program issues an error message and requests the user provides a valid input. if the user does not enter a number...
Write a program for hotel booking system using C++ Program Requirement 1. You can write any...
Write a program for hotel booking system using C++ Program Requirement 1. You can write any program based on the title assigned. 2. The program must fulfill ALL the requirements below. The requirements listed below are the MINIMUM requirement. Your program may extend beyond the requirements if needed. a) Create at least one (1) base class. b) Create at least two (2) derived classes that inherit from the base class created in 2(a). c) Create at least one (1) object...
Write a program in c++ using only while and for loops . Use of arrays and...
Write a program in c++ using only while and for loops . Use of arrays and functions is not allowed. Given the first value, generate the next ten terms of the sequence like 1, 2, 4, 8, 16, 22, 26, 38, 62, 74, 102, 104, … Explaination with code is required.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT