programming
posted by AB .
A hotel’s occupancy rate is calculated as follows: Occupancy rate = number of rooms occupied total number of rooms Write a program that calculates the occupancy rate for each fl oor of a hotel. The program should start by asking for the number of fl oors in the hotel. A loop should then iterate once for each fl oor. During each iteration, the loop should ask the user for the number of rooms on the fl oor 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.
**I believe I have the program done correctly, I just can't figure out how to get it not to accept a number less than 10 for the number of rooms on a floor.** Here is the code:
package hotel;
import java.util.Scanner;
public class Hotel {
public static void main(String[]args) {
int floors, occupiedRooms = 0, totalRooms = 0;
Scanner input = new Scanner(System.in);
System.out.print("How many floors are present: ");
floors = input.nextInt();
for(int i = 1; i <= floors; i++) {
System.out.print("Level " + i + ": How many rooms are there: ");
int totalRoomsOnLevel = input.nextInt();
System.out.print("Level " + i + ":How many are occupied: ");
int occupiedRoomsOnLevel = input.nextInt();
System.out.println();
totalRooms += totalRoomsOnLevel;
occupiedRooms += occupiedRoomsOnLevel;
}
System.out.println();
System.out.println("Total hotel rooms: " + totalRooms);
int vacantRooms = totalRooms  occupiedRooms;
System.out.println("Total vacant rooms: " + vacantRooms);
double occupancyRate = (double)occupiedRooms / totalRooms;
System.out.println("Occupancy rate: " + occupancyRate);
}
}

Your code looks carefully thought out.
For making sure there are 10 storeys or more, you can modify the input segment:
System.out.print("How many floors are present: ");
floors = input.nextInt();
while(floors<10){
// print Number of floors must be at least 10
floors = input.nextInt();
}
But this would continue indefinitely until user enters a number greater than 10.
A better way is to use a forloop to loop a maximum (say 5) of times after which a message will appear and the program terminates. 
I'm sorry. I think I was confusing. There can't be less than 1 for the number of floors, but has to be at least 10 for the number of rooms on a floor.

It would be along the same lines, just change floors to rooms, and for floors, change 10 to 1 for the number of floors.

I got it. Thanks so much. You're awesome.

You did most of the work, so you deserve the credit too!
Respond to this Question
Similar Questions

Algebra
I have two questions... 1.Lenear system...If you are painting the white lines around the perimeter of a tennis court. You measure and find that the perimeter is 228ft and the lenght is 42ft longer that the width...I need to write a … 
math/algebra
I need help in solving this word problem using linear system equation...I.m not sure how to start,,, A hotel rents a double occupanch room for $20 more than a single occupancy room. One night, the hotel took in $3115 after renting … 
Managerial Economics
A CA resort offers yearround activities and the resort's operating costs are essentially the same in winter and summer. Mgmt charges higher nightly rates in the winter, when its average occupancy rate is 75%, than in the summer, when … 
Managerial Economics
A CA resort offers yearround activities and the resort's operating costs are essentially the same in winter and summer. Mgmt charges higher nightly rates in the winter, when its average occupancy rate is 75%, than in the summer, when … 
Production & Operations Mgmt in Business
If someone could help me, I am truly desperate here. I am struggle with this problem. – Simple Linear Regression Applications Interpretation and Use of Computer Output (Results) (1) The management of an international hotel chain … 
Math
A local motel has 100 rooms. The occupancy rate for the winter months is 60%. Find the probability that in a given winter month more than 65 rooms will be rented. Use the normal distribution to approximate the binomial distribution. 
PreCalculus
The Hotel Bellville has 400 rooms. Currently the hotel is filled . The daily rental is $ 250 per room. For every $ 14 increase in rent the demand for rooms decreases by 5 rooms. Let x = the number of $ 14 increases that can be made. … 
math
Help pleaseeee The Hotel Regal has 500 rooms. Currently the hotel is filled. The daily rental is $ 400 per room. For every $4 increase in rent the demand for rooms decreases by 8 rooms. Let x be the number of rooms that are being rented … 
Math
The Hotel Regal has 600 rooms. Currently the hotel is filled . The daily rental is $ 250 per room. For every $ 4 increase in rent the demand for rooms decreases by 4 rooms. Let x = the number of $ 4 increases that can be made. What … 
precalculus
The Hotel Thomasina has 500 rooms. Currently the hotel is filled . The daily rental is $ 1000 per room. For every $ 4 increase in rent the demand for rooms decreases by 8 rooms. Let x = the number of $ 4 increases that can be made. …