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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Need help with looping!

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help with looping!

    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!


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Need help with looping!

    One post is enough. Please do not post the same thread twice and keep the conversation in your original post here.
    Last edited by copeg; October 29th, 2011 at 04:13 PM.

Similar Threads

  1. not looping properly, please help.
    By nakedtriple in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 28th, 2011, 08:31 AM
  2. Help in looping
    By endframe in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 28th, 2010, 03:24 PM
  3. looping method
    By dcshoecousa in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 5th, 2010, 09:19 PM
  4. Help with Object Looping
    By a swan ting in forum Loops & Control Statements
    Replies: 12
    Last Post: November 24th, 2010, 06:43 PM
  5. [SOLVED] looping, for,while,do-while.
    By chronoz13 in forum Loops & Control Statements
    Replies: 4
    Last Post: August 6th, 2009, 01:32 PM