Basically im writing a java code for class which we do once a week but this week i am completely stumped. I have done the looping process before but in this case it is different because after each loop it needs to re-do 2 steps. I would really appreciate any kind of help i can get. The following is my task and what i have so far:
A hotels 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 floor of a hotel. The program should start by asking for the number of floors in the hotel.
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.
{// begin class
public static void main (String[]args)
{// begin method
String inputString; //for reading input
double floors; //number of floors in the hotel
double rooms; //number of rooms on the floor
double occupied; //number of rooms occupied
int number; // loop control variable
// Create a DecimalFormat object.
DecimalFormat formatter = new DecimalFormat("#0.00");
//get number of floors in hotel
inputString = JOptionPane.showInputDialog(null, "What is the number of floors in the hotel?");
//convert input to double
floors = Double.parseDouble(inputString);
//get number of rooms on the floor
inputString = JOptionPane.showInputDialog(null, "What is the number of rooms on the floor?");
//convert input to double
rooms = Double.parseDouble(inputString);
//get the number of rooms that are occupied
inputString = JOptionPane.showInputDialog(null, "What is the number of rooms that are occupied?");
//convert input to double
occupied = Double.parseDouble(inputString);
}
//end the program
System.exit(0);
}//end method
I am not looking for you to complete the code for me. I just need to know how to loop and repeat the questions given in the task. Thank you!