Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

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!

buuumpppppppp

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.

...edited by moderator

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