calculates the occupancy rate for each floor of a hotel. 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 am having trouble getting the Occupancy Rate calculation to work.

import javax.swing.JOptionPane; import java.text.DecimalFormat; /** This program calculates a running total. */ public class Occupancy { public static void main(String[] args) { int floors; //Number of floors int rooms; //Number of rooms int occupied; //Occupied rooms int totalOccupied; //Accumulator int totalRooms; //Accumulator String input; // To hold the user's input int vacant; //To hold the number of vacant rooms final int MIN_FLOORS = 1; //Minimum amount of floors final int MIN_ROOMS = 10; //Minimum amount of rooms per floor double occRate; //Occupancy Rate int totalFloors; //accumulator // Get the number of floors. input = JOptionPane.showInputDialog("How many floors are in the hotel?"); floors = Integer.parseInt(input); //Validate the number of floors entered. while (floors < MIN_FLOORS) { input =JOptionPane.showInputDialog("You have Entered a value less than the 1"+ "How many Floors are in the Hotel? "); } // Set the accumulator to 0. totalRooms = 0; totalOccupied = 0; occRate = 0; DecimalFormat formatter = new DecimalFormat("#,##0.0"); //Get the number of rooms per floor and calculate a running total for (int count = 1; count <= floors; count++) { input = JOptionPane.showInputDialog("Enter the number of rooms on floor #" + count + ":"); rooms = Integer.parseInt(input); while (rooms < 10) { input = JOptionPane.showInputDialog("You have entered the number of rooms less than 10 per floor! Please enter the number of floors:"); } totalRooms += rooms; // Add rooms to totalRooms. input = JOptionPane.showInputDialog("Enter the number of rooms that are OCCUPIED on floor #" + count + ":"); occupied = Integer.parseInt(input); totalOccupied += occupied; // Add occupied to totalOccupied. } //Calculate the number of vacant rooms. vacant = totalRooms - totalOccupied; //Calculate the Occupancy rate. occRate = (double)(totalOccupied / totalRooms); // Display the results. JOptionPane.showMessageDialog(null, "There are " + totalRooms + " rooms in the hotel. " + "Out of those, " + totalOccupied + " are occupied, " + + vacant + " are vacant, &" + " the occupancy rate is " + occRate + "%" ); System.out.println(occRate); System.exit(0); } }

This post has been edited by **modi123_1**: 02 October 2012 - 02:53 PM

Reason for edit:: fixed title - this isn't a challenge.