Wednesday
November 26, 2014

Homework Help: programming

Posted by AB on Tuesday, May 22, 2012 at 9:00pm.

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);
}
}

Answer this Question

First Name:
School Subject:
Answer:

Related Questions

math/algebra - I need help in solving this word problem using linear system ...
Production & Operations Mgmt in Business - If someone could help me, I am truly ...
Algebra - I have two questions... 1.Lenear system...If you are painting the ...
Math - A local motel has 100 rooms. The occupancy rate for the winter months is ...
Managerial Economics - A CA resort offers year-round activities and the resort'...
Managerial Economics - A CA resort offers year-round activities and the resort's...
economics - A New Hampshire resort offers year-round activities: in winter, ...
economics - A New Hampshire resort offers year-around activities: in winter, ...
math - Help pleaseeee The Hotel Regal has 500 rooms. Currently the hotel is ...
math - a hotel chain charges $120 per room and rents an avg of 40 rooms per ...

Search
Members