• October 29th, 2011, 09:58 AM
crsoccerplayer6
Basically im writing a java code for class which we do once a week but this week i am completely stumped. I cant seem to completely understand the looping process and would really appreciate any kind of help i can get one where and how to insert it. 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
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
}//endclass

Any help at all is greatly appreciated, thank you!
• October 29th, 2011, 11:50 AM
crsoccerplayer6
buuumpppppppp
• October 29th, 2011, 11:58 AM
Tjstretch
3 Things:
• Bumping threads makes it look like someone has already replied and is actually quite likely to make less people reply. Also, it makes it seem like you think your time is more valuable than everyone else's here on the forums. Most likely, 75% of the posts here are 'urgent'. If you want immediate help you can pay for it, I think the average is \$2.50 a minute over at LivePerson.
• Highlight your code with bb code.
• Please post your specific problem, that makes it more likely for people to be able to give relevant information. You just posted some code and the assignment. Are you getting an error? Are you not sure how to create loops? Specific Questions get Specific Answers.
• October 29th, 2011, 12:18 PM
Saurabh Mittal
...edited by moderator
• October 29th, 2011, 12:22 PM
Tjstretch
Sigh, if you didn't read my last post, code tags save everyone a LOT of trouble. I do not generally read code that isn't in tags, but because your post just contains code, I'm willing to bet it's a full solution. You should read: The Problem with Spoon-feeding
• October 29th, 2011, 01:59 PM
copeg