Hi! I need help in understanding why the average does not calculate the data from my accumulator after the for loop ends.
We were asked for our homework to create a "hotel occupancy" program which asks the user to put in the number of floors, the number of rooms in a floor, and the number of rooms occupied.
- 13th floor is skipped
- Number of floors should NOT be less than 1
- Number of rooms in a floor should NOT be less than 10
- Occupied rooms should NOT be greater than number of rooms
The value for totalRooms and totalOccuRooms works but the average doesn't. Need help with this one.
public class Lab7a //Hotel Occupancy
public static void main(Stringargs)
Scanner keyboard = new Scanner(System.in);
int floorTotal, totalRooms = 0;
int floorOccu, totalOccuRooms = 0;
System.out.println("How many floors are there in the hotel?");
numFloors = keyboard.nextInt();
}while (numFloors < 1);
for (int counter = 1; counter <= numFloors; counter++)
if (counter == 13)
System.out.println("\nHow many rooms are there in floor " + counter + "?");
floorTotal = keyboard.nextInt();
}while (floorTotal < 10);
System.out.println("How many are occupied?");
floorOccu = keyboard.nextInt();
}while (floorOccu < 0 || floorOccu > floorTotal);
totalRooms += floorTotal;
totalOccuRooms += floorOccu;
average = (int)((totalOccuRooms/totalRooms)*100);
System.out.println("\nThe Hotel has " + totalRooms + " rooms in total.");
System.out.println(totalOccuRooms + " of the rooms are occupied.");
System.out.printf("%d of the rooms are occupied.", average);
This will result to this:
How many floors are there in the hotel?
How many rooms are there in floor 1?
How many are occupied?
The Hotel has 100 rooms in total.
96 of the rooms are occupied.
0 of the rooms are occupied.