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. The equation is: Occupancy rate = number of rooms occupied / total number of rooms. As far as the code is concerned, I think it is good except I don't know how to make it to iterate once for each floor. Here's what I have:
import java.util.Scanner;
public class Hotel
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
String input; //To hold the user's input
final int MIN_FLOORS = 1; //Minimum amount of floors
final int MIN_ROOMS = 10; //Minimum amount of rooms per floor
int floors; //Number of floors in hotel
int rooms; //Number of available rooms in each floor
int occrooms; //Number of rooms occupied
int totalrooms; //Number of total rooms
double occrate; //Occupancy rate
int vacant; //Number of vacant rooms
System.out.println("How many floors are in the hotel? "); //Get the number of floors in the hotel
do //Validate the number entered.
{
System.out.println("The number of floors " + "must be at least " + MIN_FLOORS);
floors = keyboard.nextInt();
}
while (floors < MIN_FLOORS);
System.out.println("How many rooms are on each floor?"); //Get the number of rooms in each floor
do //Validate the number entered.
{
System.out.println("The number " + "of rooms must be greater than " + MIN_ROOMS);
rooms = keyboard.nextInt();
}
while(rooms < MIN_ROOMS); //Get the amount of rooms occupied.
System.out.println("How many rooms are occupied?");
occrooms = keyboard.nextInt();
totalrooms = (floors * rooms);
occrate = ((double)occrooms / totalrooms);
vacant = (totalrooms - occrooms);
//Display the results
System.out.println("There " + "are " + totalrooms + " total rooms in the hotel, the number of rooms occupied are " +
occrooms + ", " + vacant + " rooms are vacant, and the occupancy rate for the hotel is " + occrate + ".");
//End the program.
System.exit(0);
}
}
Thank you!

New Topic/Question
Reply




MultiQuote








|