Hotel Occupancy rate not working

Page 1 of 1

0 Replies - 240 Views - Last Post: 03 October 2012 - 07:07 PM Rate Topic: -----

#1 itsjay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 03-October 12

Hotel Occupancy rate not working

Posted 03 October 2012 - 07:07 PM

The program should start by asking for the number of floors that the hotel has. 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 number less than one for the number of floors. Do not accept a number less than 10 for the number of rooms on a floor.

I'm getting a wrong occupancy rate. the 'rooms' and 'occupied' keeps resetting after each loop.

i'm very new to this so please help!

Thanks
/*

this program determines the occupancy rate of a hotel

*/
import java.util.Scanner;


	public class HotelOccupancy
	{
		
		public static void main ( String [] args) 
		{

Scanner keyboard = new Scanner(System.in);


	int floors = 0;					//number of floors
	int rooms =0;					//number of rooms
	int occupied = 0;				//number of occupied rooms
	final int MIN_FLOOR = 1;		//minimum number of floors
	final int MIN_ROOMS = 10;		// minimum number of rooms
	double occupancy = 0;			//occupancy rate
	int total;					//total number of rooms
	int vacant = 0;					//number of vacant rooms
	
	//number of floors
	System.out.println("Enter the number of floors");

	
	//to validate the number of floors
	do
	{
		floors = keyboard.nextInt();
		System.out.println("Floors have to be more than 1");
	}
	while (floors <= MIN_FLOOR);
	
	//to insert a blank line
	System.out.println();
	
		for (int i = 0; i < floors; ++i)
	{
		// number of rooms on each floor
		System.out.println("Please enter the number of rooms on floor " + i);
			rooms = keyboard.nextInt();
		
		//room occupied per floor
		System.out.println("How many rooms on floor " + i + " are occupied");
			occupied = keyboard.nextInt();
			
		
			
	}
	
	//calculations
	total = (floors * rooms);
	vacant = (total - occupied);
	occupancy = ((double)occupied / total);	
	
	
	
	
			
	
}	
}



Is This A Good Question/Topic? 0
  • +

Page 1 of 1