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 18 of 18

Thread: Project Nursing Home Due Tonight Help

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Project nursing homes

    Having major problems getting this program due tonight. Never had a problem with the basic programs as a beginner but this is too much. It's due tonight and no I didn't procrastinate I'm just not good at programming yet.
    I have the code displayed here and well as my assignment (ie input and output expected). Please help me, I understand the concepts but putting it into a real complete program is killing me. Love to code but getting overwhelmed.



    __________________________________________________ ___________________________________________

    import java.text.DecimalFormat; //Needed to format occupancy rate as percentage
    import java.util.Scanner; //Needed for the scanner class

    // This program was created by Michael Morris

    /** This program will determine the occupancy rate for multiple
    nursing home

    */

    public class Project2Morris
    {

    public static void main(String[] args)
    {

    int numBuildings; //Number of nursing homes
    int numfloors; //Number of floors in the nursing home
    int numRoomsFloor; //Number of rooms on the floor
    int numOccupiedRooms; //Number of occupied rooms on the floor
    int vacantRooms;
    double occupancyRate;
    int totalNumBuildings; //Accumulator for number of buildings

    DecimalFormat formatter = new DecimalFormat("%#0");
    Scanner keyboard = new Scanner (System.in);

    totalNumBuildings = 0;

    System.out.print("Enter the number of nursing homes: ");
    numBuildings = keyboard.nextInt();
    System.out.println("Nursing Home:" +numBuildings);


    totalNumBuildings = numBuildings;


    while (numBuildings<=0)
    {

    System.out.println("Invalid entry: Number of buildings must be greater than 0.");
    System.out.println("Reenter the number of buildings:");
    numBuildings = keyboard.nextInt();
    }



    System.out.print("How many floors are in the nursing home ?");
    numfloors = keyboard.nextInt();
    while (numfloors<=0)
    {
    System.out.println("Invalid entry: Floors must be greater than 0.");
    System.out.println("Reenter the number of floors in nursing home.");
    numfloors = keyboard.nextInt();
    }

    System.out.print("How many rooms does floor have?");
    numRoomsFloor = keyboard.nextInt();
    System.out.println("Number of rooms:" +numRoomsFloor);

    while (numRoomsFloor<10)
    {
    System.out.println("Invalid entry: Rooms cannot be less than 10.");
    System.out.println("Reenter the number of Rooms.");
    numRoomsFloor = keyboard.nextInt();
    }
    System.out.println("How many occupied rooms are on the floor?");
    numOccupiedRooms = keyboard.nextInt();
    while (numOccupiedRooms<=0)
    {
    System.out.println("Invalid entry: Occupied rooms must be 0 or greater.");
    System.out.println("Reenter number of occupied rooms on the floor.");
    numOccupiedRooms = keyboard.nextInt();
    }
    System.out.println("Occupied Rooms:" +numOccupiedRooms);

    occupancyRate = numRoomsFloor / numOccupiedRooms;
    vacantRooms = numRoomsFloor - numOccupiedRooms;
    System.out.println("Vacant rooms:" +vacantRooms);

    System.out.println("occupancy rate:" +occupancyRate);

    if (occupancyRate>75)
    {
    System.out.println("Occupancy Rate is High");
    }
    else if (occupancyRate==50 && occupancyRate==74)
    {
    System.out.println("Occupancy Rate is Average");
    }
    else if (occupancyRate>50)
    {
    System.out.println("Occupancy Rate is Low");








    }


    }
    }


    __________________________________________________ ____________________________________________


    Project Description

    The owner of the Sunshine Nursing Home would like you to modify your program so the program can be used to determine the occupancy rate for multiple nursing homes.

    Modify Project 1 as follows:

    Input validation:
    • Do not accept a value less than 1 for the number of nursing homes.
    • Do not accept a value less than 1 for the number of floors in a nursing home.
    • Do not accept a number less than 10 for the number of rooms on a floor.
    • Do not accept a number less than 0 for the number of occupied rooms.
    • Do not accept a number for occupied rooms that is higher than the actual number of rooms for the related floor

    The program should display:

    • The nursing home number.
    • The total number of rooms in each nursing home.
    • The total number of occupied rooms in each nursing home.
    • The total number of vacancies in each nursing home.
    • The occupancy rate for each nursing home (the occupancy rate should be displayed as a percentage).
    • The program should display "Occupancy Rate is High" if the occupancy rate is above 75%; “Occupancy Rate is Average” if the occupancy rate is 50 – 74% and “Occupancy Rate is Low” if the occupancy rate is below 50%.

    Sample Input and Output for Two Nursing Homes


    Sample Input Number of buildings: 0
    Invalid entry: Number of buildings must be greater than 0.
    Reenter the number of buildings: 2

    How many floors are in Nursing Home 1? 0
    Invalid entry: Floor(s) must be greater than 0.
    Reenter the number of floors: 1
    How many rooms does floor 1 have? 9
    Invalid entry: Rooms cannot be less than 10.
    Reenter the number of rooms: 20
    How many occupied rooms are on floor 1? -1
    Invalid entry: Occupied rooms must be 0 or greater. Reenter: 15

    Nursing Home 1
    Number of rooms: 20
    Occupied rooms: 15
    Vacant rooms: 5
    Occupancy rate: 75%
    Occupancy Rate is High

    How many floors are in Nursing Home 2? 3
    How many rooms does floor 1 have? 20
    How many occupied rooms are on floor 1: 5
    How many rooms does floor 2 have? 20
    How many occupied rooms are on floor 2? 8
    How many rooms does floor 3 have? 20
    How many occupied rooms are on floor 3? 11


    Nursing Home 2
    Number of rooms: 60
    Occupied rooms: 24
    Vacant rooms: 36
    Occupancy rate: 40%
    Occupancy Rate is Low

    Compiled and ran the code but this is not what my professor is looking for. Not sure were to start.


    Enter the number of nursing homes: 2
    Nursing Home:2
    How many floors are in the nursing home ?1
    How many rooms does floor have?20
    Number of rooms:20
    How many occupied rooms are on the floor?
    15
    Occupied Rooms:15
    Vacant rooms:5
    occupancy rate:1.0

    --- Update ---

    mY occucpancy caculations aren't correct and my if else if statements to display whether the occupancy rate is high, average, or low
    doesn't work. Not sure if I'm doing the number of buildings right should this be looping.

    Need help badly
    I have while loops to make sure I have the proper input. Other than that pretty lost. Help get me started
    Not looking for you to code it. Just an overall structure of whtat to go on.



    Sample Input


    Number of buildings: 0
    Invalid entry: Number of buildings must be greater than 0.
    Reenter the number of buildings: 2

    How many floors are in Nursing Home 1? 0
    Invalid entry: Floor(s) must be greater than 0.
    Reenter the number of floors: 1
    How many rooms does floor 1 have? 9
    Invalid entry: Rooms cannot be less than 10.
    Reenter the number of rooms: 20
    How many occupied rooms are on floor 1? -1
    Invalid entry: Occupied rooms must be 0 or greater. Reenter: 15


    Nursing Home 1
    Number of rooms: 20
    Occupied rooms: 15
    Vacant rooms: 5
    Occupancy rate: 75%
    Occupancy Rate is High

    How many floors are in Nursing Home 2? 3
    How many rooms does floor 1 have? 20
    How many occupied rooms are on floor 1: 5
    How many rooms does floor 2 have? 20
    How many occupied rooms are on floor 2? 8
    How many rooms does floor 3 have? 20
    How many occupied rooms are on floor 3? 11


    Nursing Home 2
    Number of rooms: 60
    Occupied rooms: 24
    Vacant rooms: 36
    Occupancy rate: 40%
    Occupancy Rate is Low

    --- Update ---

    Can i please get a flowchart or at least a partiap one. Only been coding 8 wks and Have an Assignment Due That Pve Worked On For 2 days. Please Help Dont Want To Fail This Projrct. Ill Write My Own Code. But It Seems Theres Some Kind Of Loop When I Pick Numbr Of Buipdings That Will Allow to Keep Inputing Ingormation For As many Buildings As I Specify. Look at Sample Input 1 And 2 Finding The Input and Output For 1 is Simple But For Many Not Sure.

    This is to compute the occupancy rate for multiple nursing homes very confused need help

    _Sample Input_________________________

    Number of buildings: 0
    Invalid entry: Number of buildings must be greater than 0.
    Reenter the number of buildings: 2

    How many floors are in Nursing Home 1? 0
    Invalid entry: Floor(s) must be greater than 0.
    Reenter the number of floors: 1
    How many rooms does floor 1 have? 9
    Invalid entry: Rooms cannot be less than 10.
    Reenter the number of rooms: 20
    How many occupied rooms are on floor 1? -1
    Invalid entry: Occupied rooms must be 0 or greater. Reenter: 15

    Nursing Home 1
    Number of rooms: 20
    Occupied rooms: 15
    Vacant rooms: 5
    Occupancy rate: 75%
    Occupancy Rate is High

    How many floors are in Nursing Home 2? 3
    How many rooms does floor 1 have? 20
    How many occupied rooms are on floor 1: 5
    How many rooms does floor 2 have? 20
    How many occupied rooms are on floor 2? 8
    How many rooms does floor 3 have? 20
    How many occupied rooms are on floor 3? 11


    Nursing Home 2
    Number of rooms: 60
    Occupied rooms: 24
    Vacant rooms: 36
    Occupancy rate: 40%
    Occupancy Rate is Low


    Can i please get a flowchart or at least a partiap one. Only been coding 8 wks and Have an Assignment Due That Pve Worked On For 2 days. Please Help Dont Want To Fail This Projrct. Ill Write My Own Code. But It Seems Theres Some Kind Of Loop When I Pick Numbr Of Buipdings That Will Allow to Keep Inputing Ingormation For As many Buildings As I Specify. Look at Sample Input 1 And 2 Finding The Input and Output For 1 is Simple But For Many Not Sure.

    Here is my code:


    import java.text.DecimalFormat; //Needed to format occupancy rate as percentage
    import java.util.Scanner; //Needed for the scanner class

    // This program was created by Michael Morris

    /** This program will determine the occupancy rate for multiple
    nursing home

    */

    public class Project2Morris
    {

    public static void main(String[] args)
    {

    int numBuildings; //Number of nursing homes
    int numfloors; //Number of floors in the nursing home
    int numRoomsFloor; //Number of rooms on the floor
    int numOccupiedRooms; //Number of occupied rooms on the floor
    int vacantRooms;
    double occupancyRate;
    int totalNumBuildings; //Accumulator for number of buildings

    DecimalFormat formatter = new DecimalFormat("%#0");
    Scanner keyboard = new Scanner (System.in);

    totalNumBuildings = 0;

    System.out.print("Enter the number of nursing homes: ");
    numBuildings = keyboard.nextInt();
    System.out.println("Nursing Home:" +numBuildings);


    totalNumBuildings = numBuildings;


    while (numBuildings<=0)
    {

    System.out.println("Invalid entry: Number of buildings must be greater than 0.");
    System.out.println("Reenter the number of buildings:");
    numBuildings = keyboard.nextInt();
    }



    System.out.print("How many floors are in the nursing home ?");
    numfloors = keyboard.nextInt();
    while (numfloors<=0)
    {
    System.out.println("Invalid entry: Floors must be greater than 0.");
    System.out.println("Reenter the number of floors in nursing home.");
    numfloors = keyboard.nextInt();
    }

    System.out.print("How many rooms does floor have?");
    numRoomsFloor = keyboard.nextInt();
    System.out.println("Number of rooms:" +numRoomsFloor);

    while (numRoomsFloor<10)
    {
    System.out.println("Invalid entry: Rooms cannot be less than 10.");
    System.out.println("Reenter the number of Rooms.");
    numRoomsFloor = keyboard.nextInt();
    }
    System.out.println("How many occupied rooms are on the floor?");
    numOccupiedRooms = keyboard.nextInt();
    while (numOccupiedRooms<=0)
    {
    System.out.println("Invalid entry: Occupied rooms must be 0 or greater.");
    System.out.println("Reenter number of occupied rooms on the floor.");
    numOccupiedRooms = keyboard.nextInt();
    }
    System.out.println("Occupied Rooms:" +numOccupiedRooms);

    occupancyRate = numRoomsFloor / numOccupiedRooms;
    vacantRooms = numRoomsFloor - numOccupiedRooms;
    System.out.println("Vacant rooms:" +vacantRooms);

    System.out.println("occupancy rate:" +occupancyRate);

    if (occupancyRate>75)
    {
    System.out.println("Occupancy Rate is High");
    }
    else if (occupancyRate==50 && occupancyRate==74)
    {
    System.out.println("Occupancy Rate is Average");
    }
    else if (occupancyRate>50)
    {
    System.out.println("Occupancy Rate is Low");








    }


    }
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Project Nursing Home Due Tonight Help

    What help do you need? Where are you stuck? Or are you just hoping for a group effort?

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Revised Project Nursing Home

    Do the project in separate steps.
    Display messages and get user responses
    Compute values and display them.

    Later when that works, work on using a loop for multiple sets of input.

    What do you have coded now? Be sure to wrap posted code in code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Revised Project Nursing Home

    Please explain what you have finished and what are having problems with.

    What is on the console when the program executes?
    On Windows: To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.


    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Oct 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Revised Project Nursing Home

    import java.text.DecimalFormat; //Needed to format occupancy rate as percentage
    import java.util.Scanner; //Needed for the scanner class

    // This program was created by Michael Morris

    /** This program will determine the occupancy rate for multiple
    nursing home

    */

    public class Project2Morris
    {

    public static void main(String[] args)
    {

    int numBuildings; //Number of nursing homes
    int numfloors; //Number of floors in the nursing home
    int numRoomsFloor; //Number of rooms on the floor
    int numOccupiedRooms; //Number of occupied rooms on the floor
    int vacantRooms;
    double occupancyRate;
    int totalNumBuildings; //Accumulator for number of buildings

    DecimalFormat formatter = new DecimalFormat("%#0");
    Scanner keyboard = new Scanner (System.in);

    totalNumBuildings = 0;

    System.out.print("Enter the number of nursing homes: ");
    numBuildings = keyboard.nextInt();
    System.out.println("Nursing Home:" +numBuildings);


    totalNumBuildings = numBuildings;


    while (numBuildings<=0)
    {

    System.out.println("Invalid entry: Number of buildings must be greater than 0.");
    System.out.println("Reenter the number of buildings:");
    numBuildings = keyboard.nextInt();
    }



    System.out.print("How many floors are in the nursing home ?");
    numfloors = keyboard.nextInt();
    while (numfloors<=0)
    {
    System.out.println("Invalid entry: Floors must be greater than 0.");
    System.out.println("Reenter the number of floors in nursing home.");
    numfloors = keyboard.nextInt();
    }

    System.out.print("How many rooms does floor have?");
    numRoomsFloor = keyboard.nextInt();
    System.out.println("Number of rooms:" +numRoomsFloor);

    while (numRoomsFloor<10)
    {
    System.out.println("Invalid entry: Rooms cannot be less than 10.");
    System.out.println("Reenter the number of Rooms.");
    numRoomsFloor = keyboard.nextInt();
    }
    System.out.println("How many occupied rooms are on the floor?");
    numOccupiedRooms = keyboard.nextInt();
    while (numOccupiedRooms<=0)
    {
    System.out.println("Invalid entry: Occupied rooms must be 0 or greater.");
    System.out.println("Reenter number of occupied rooms on the floor.");
    numOccupiedRooms = keyboard.nextInt();
    }
    System.out.println("Occupied Rooms:" +numOccupiedRooms);

    occupancyRate = numRoomsFloor / numOccupiedRooms;
    vacantRooms = numRoomsFloor - numOccupiedRooms;
    System.out.println("Vacant rooms:" +vacantRooms);

    System.out.println("occupancy rate:" +occupancyRate);

    if (occupancyRate>75)
    {
    System.out.println("Occupancy Rate is High");
    }
    else if (occupancyRate==50 && occupancyRate==74)
    {
    System.out.println("Occupancy Rate is Average");
    }
    else if (occupancyRate>50)
    {
    System.out.println("Occupancy Rate is Low");








    }


    }
    }




    ----jGRASP exec: java Project2Morris

    Enter the number of nursing homes: 2
    Nursing Home:2
    How many floors are in the nursing home ?1
    How many rooms does floor have?20
    Number of rooms:20
    How many occupied rooms are on the floor?
    15
    Occupied Rooms:15
    Vacant rooms:5
    occupancy rate:1.0

    ----jGRASP: operation complete.

    ----jGRASP exec: java Project2Morris

    Enter the number of nursing homes: 2
    Nursing Home:2
    How many floors are in the nursing home ?1
    How many rooms does floor have?20
    Number of rooms:20
    How many occupied rooms are on the floor?
    15
    Occupied Rooms:15
    Vacant rooms:5
    occupancy rate:1.0

    ----jGRASP: operation complete.

    --- Update ---

    using jgrasp

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Project Nursing Home Due Tonight Help

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    What are you having problems with?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Oct 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Project Nursing Home Due Tonight Help

    not sure how to do that. Im a beginner

    --- Update ---

    using jgrasp

    --- Update ---

    my occupancy rate doesn't compute right also all my if else if statements aren't being executed to get my high, low or average occupancy rates. Next thing after that is how to get it to loop for my next building if I enter more than 1. Say I enter 4. Or 3 floors for my number of floors.

    --- Update ---

    Hope I'm breaking it down a little more. Im working at my job and shouldn't be on the computer getting homework done lol

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Project Nursing Home Due Tonight Help

    my occupancy rate doesn't compute right
    what value is computed? what should the value be? Check your math to see how it should be computed. The rates would be from 0 to 100%
    How do you compute percent?

    To wrap the code in code tags:
    put this in front of the code: [code]
    and this after: [/code]
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Oct 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Project Nursing Home Due Tonight Help

    import java.text.DecimalFormat; //Needed to format occupancy rate as percentage
    import java.util.Scanner; //Needed for the scanner class

    // This program was created by Michael Morris
    [/code][/code]

    /** This program will determine the occupancy rate for multiple 
    nursing home
     
    */

    public class Project2Morris
    {[/code]

    public static void main(String[] args)
    {[/code]

    int numBuildings; //Number of nursing homes
    int numfloors; //Number of floors in the nursing home
    int numRoomsFloor; //Number of rooms on the floor
    int numOccupiedRooms; //Number of occupied rooms on the floor
     int vacantRooms;
    double occupancyRate;
    int totalNumBuildings; //Accumulator for number of buildings

     DecimalFormat formatter = new DecimalFormat("%#0")
    ;
     Scanner keyboard = new Scanner (System.in);

    totalNumBuildings = 0;

     System.out.print("Enter the number of nursing homes: ");
     numBuildings = keyboard.nextInt();
     System.out.println("Nursing Home:" +numBuildings);


    totalNumBuildings = numBuildings;


    while (numBuildings<=0)
    {

     System.out.println("Invalid entry: Number of buildings must be greater than 0.");
     System.out.println("Reenter the number of buildings:");
    numBuildings = keyboard.nextInt();[/code]
    }
     
     
     
         [code] System.out.print("How many floors are in the nursing home ?");
    numfloors = keyboard.nextInt();[/code]
      while (numfloors<=0)
     {
     System.out.println("Invalid entry: Floors must be greater than 0.");
     System.out.println("Reenter the number of floors in nursing home.");
    numfloors = keyboard.nextInt();[/code]
     }

    System.out.print("How many rooms does floor have?");
    numRoomsFloor = keyboard.nextInt();[/code]
     System.out.println("Number of rooms:" +numRoomsFloor);

     while (numRoomsFloor<10)
     {
    System.out.println("Invalid entry: Rooms cannot be less than 10.");
    System.out.println("Reenter the number of Rooms.");
    numRoomsFloor = keyboard.nextInt();[/code]
     }
    System.out.println("How many occupied rooms are on the floor?");
    numOccupiedRooms = keyboard.nextInt();[/code]
     while (numOccupiedRooms<=0)
    {
    [/code]
     System.out.println("Invalid entry: Occupied rooms must be 0 or greater.");
       [code]  System.out.println("Reenter number of occupied rooms on the floor.");
    numOccupiedRooms = keyboard.nextInt(); [/code]
    [code]}
     System.out.println("Occupied Rooms:" +numOccupiedRooms);

     occupancyRate = numRoomsFloor / numOccupiedRooms;
     vacantRooms = numRoomsFloor - numOccupiedRooms;
    System.out.println("Vacant rooms:" +vacantRooms);

     System.out.println("occupancy rate:" +occupancyRate);

    if (occupancyRate>75)
    [code] {
    System.out.println("Occupancy Rate is High");
    [code] }
     else if (occupancyRate==50 && occupancyRate==74)
    {
    System.out.println("Occupancy Rate is Average");
     }
         [code] else if (occupancyRate>50)
    [/code]
    {
     System.out.println("Occupancy Rate is Low");
    ______________________________
    Enter the number of nursing homes: 2
    Nursing Home:2
    How many floors are in the nursing home ?1
    How many rooms does floor have?20
    Number of rooms:20
    How many occupied rooms are on the floor?
    15
    Occupied Rooms:15
    Vacant rooms:5
    occupancy rate:1.0







      }


      }
    }


    --- Update ---

    Hope someone can help I have a deadline at 11 p.m

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Project Nursing Home Due Tonight Help

    Did you look at what you posted? The tags go before and after the full contents of ALL the code, not around each statement.

    You missed answering these questions:
    what value is computed? what should the value be? Check your math to see how it should be computed. The rates would be from 0 to 100%
    How do you compute percent?

    Wrapped code would look like this:
       //  Define inner Scanner call for testing   <<<<<<<<<<<<<<<<<<<<<<<<<
       static class Scanner {                 // 4/29/13
         static java.util.Scanner myScnr;    //  Save real scanner here
     
         public Scanner(Object o) {
            if (myScnr == null) {           //   Put responses here
               myScnr = new java.util.Scanner("\nNo\n");
            }
         }
         public Scanner(java.io.File f) throws java.io.FileNotFoundException {
           if(!f.exists())
              throw new java.io.FileNotFoundException(f.getName()); 
           //?????
           System.out.println(">>> No Scanner code for file: " + f);
         }
         public int nextInt() {
            int val = myScnr.nextInt();
            System.out.println("val="+val);  //  show response and give NL
            return val;
         }
         public double nextDouble() {
           double val = myScnr.nextDouble();
            System.out.println("val="+val);
            return val;
         }
         public String nextLine() {
            String val = myScnr.nextLine();
            System.out.println("val="+val);
            return val;
         }
         public String next() {
            String val = myScnr.next();
            System.out.println("val="+val);
            return val;
         }
         public void close() {}
       } //  end testing Scanner class   <<<<<<<<<<<<<<<<<<<<<<
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Oct 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Project Nursing Home Due Tonight Help

    import java.text.DecimalFormat; //Needed to format occupancy rate as percentage
    import java.util.Scanner; //Needed for the scanner class
     
    // This program was created by Michael Morris
     
    /** This program will determine the occupancy rate for multiple 
    nursing home
     
    */
     
    public class Project2Morris
    {
     
      public static void main(String[] args)
      {
     
        int numBuildings; //Number of nursing homes
        int numfloors; //Number of floors in the nursing home
        int numRoomsFloor; //Number of rooms on the floor
        int numOccupiedRooms; //Number of occupied rooms on the floor
        int vacantRooms;
        double occupancyRate;
        int totalNumBuildings; //Accumulator for number of buildings
     
        DecimalFormat formatter = new DecimalFormat("%#0");
        Scanner keyboard = new Scanner (System.in);
     
        totalNumBuildings = 0;
     
        System.out.print("Enter the number of nursing homes: ");
        numBuildings = keyboard.nextInt(); 
     
     
     
     
     
     
        while (numBuildings<=0)
          {
     
        System.out.println("Invalid entry: Number of buildings must be greater than 0.");
        System.out.println("Reenter the number of buildings:");
                           numBuildings = keyboard.nextInt();  
        }
     
     
     
          System.out.print("How many floors are in the nursing home ?");
                            numfloors = keyboard.nextInt();
          while (numfloors<=0)
           {
          System.out.println("Invalid entry: Floors must be greater than 0.");
          System.out.println("Reenter the number of floors in nursing home.");
                            numfloors = keyboard.nextInt();
            }         
     
           System.out.print("How many rooms does floor have?");
                            numRoomsFloor = keyboard.nextInt();
     
     
          while (numRoomsFloor<10)
          {
          System.out.println("Invalid entry: Rooms cannot be less than 10.");
          System.out.println("Reenter the number of Rooms.");
                             numRoomsFloor = keyboard.nextInt();
            }
         System.out.println("How many occupied rooms are on the floor?");
                             numOccupiedRooms = keyboard.nextInt();
          while (numOccupiedRooms<=0)
         {
         System.out.println("Invalid entry: Occupied rooms must be 0 or greater.");
         System.out.println("Reenter number of occupied rooms on the floor.");
                             numOccupiedRooms = keyboard.nextInt(); 
            }
         System.out.println("Occupied Rooms:" +numOccupiedRooms);
     
         occupancyRate = numRoomsFloor / numOccupiedRooms;
         vacantRooms = numRoomsFloor - numOccupiedRooms;
         System.out.println("Vacant rooms:" +vacantRooms);
     
              System.out.println("occupancy rate:" +occupancyRate);
     
         if (occupancyRate>75)
         {
          System.out.println("Occupancy Rate is High");
          }
          else if (occupancyRate==50 && occupancyRate==74)
          {
          System.out.println("Occupancy Rate is Average");
          }
          else if (occupancyRate>50)
         {
          System.out.println("Occupancy Rate is Low");








    }


    }
    }




    ÏÏÏÏ
    ÏÏ«Ï ----jGRASP exec: java Project2Morris
    ÏϧÏ
    ¼¼§ÏEnter the number of nursing homes: 2
    ÏϧÏNursing Home:2
    ¼¼§ÏHow many floors are in the nursing home ?1
    ¼¼§ÏHow many rooms does floor have?20
    ÏϧÏNumber of rooms:20
    ÏϧÏHow many occupied rooms are on the floor?
    ¼¼§Ï15
    ÏϧÏOccupied Rooms:15
    ÏϧÏVacant rooms:5
    ÏϧÏoccupancy rate:1.0
    ÏϧÏ
    ÏÏ©Ï ----jGRASP: operation complete.
    ÏÏÏÏ
    ÏÏ«Ï ----jGRASP exec: java Project2Morris
    ÏϧÏ
    ¼¼§ÏEnter the number of nursing homes: 2
    ÏϧÏNursing Home:2
    ¼¼§ÏHow many floors are in the nursing home ?1
    ¼¼§ÏHow many rooms does floor have?20
    ÏϧÏNumber of rooms:20
    ÏϧÏHow many occupied rooms are on the floor?
    ¼¼§Ï15
    ÏϧÏOccupied Rooms:15
    ÏϧÏVacant rooms:5
    ÏϧÏoccupancy rate:1.0
    ÏϧÏ
    ÏÏ©Ï ----jGRASP: operation complete.
    ÏÏÏÏ
    ÏÏ«Ï ----jGRASP exec: java Project2Morris
    ÏϧÏ
    ¼¼§ÏEnter the number of nursing homes: 2
    ¼¼§ÏHow many floors are in the nursing home ?1
    ¼¼§ÏHow many rooms does floor have?20
    ÏϧÏHow many occupied rooms are on the floor?
    ¼¼§Ï15
    ÏϧÏOccupied Rooms:15
    ÏϧÏVacant rooms:5
    ÏϧÏoccupancy rate:1.0
    ÏϧÏ
    ÏÏ©Ï ----jGRASP: operation complete.
    ¼¼ÏÏ


    occupancyRate = numRoomsFloor / numOccupiedRooms; //This is my occupancyRate formula

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Project Nursing Home Due Tonight Help

    occupancyRate = numRoomsFloor / numOccupiedRooms; //This is my occupancyRate formula
    So if there are 100 rooms and 1 is occupied then the rate is 100/1 = 100 or 10000%
    That doesn't see right.
    I'd think the rate would be 1% (1/100 * 100)
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Oct 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Project Nursing Home Due Tonight Help

    Quote Originally Posted by Norm View Post
    So if there are 100 rooms and 1 is occupied then the rate is 100/1 = 100 or 10000%
    That doesn't see right.
    I'd think the rate would be 1% (1/100 * 100)

    Im Plugging In 20 for numRooms Divided By 15 numroomsoccupied And Getting 1.0 futhermore None Of My If Else Staements Are being Executed. Getting Very frustrated Havent Failed An Assignment Yet.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Project Nursing Home Due Tonight Help

    Do some research on how to compute percent.

    If there are 20 rooms and 15 are occupied, what percent of the rooms are occupied?

    None Of My If Else Staements Are being Executed.
    The posted code does not show the end of the if/else if statement so I can't help you without seeing all of the statements.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Oct 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Project Nursing Home Due Tonight Help

    Quote Originally Posted by Norm View Post
    Do some research on how to compute percent.

    If there are 20 rooms and 15 are occupied, what percent of the rooms are occupied?



    The posted code does not show the end of the if/else if statement so I can't help you without seeing all of the statements.
    It Should Be 75 or .75 as A Decimal. This Shouldnt Be Complicated. I Can Use Decimalformat To have It Show As A Percent If It At Least Computed As The Correct Decimal.

    --- Update ---

    My if else statements are in ealier threads at the top and middle towards the end of my program. Thank you for your time,

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Project Nursing Home Due Tonight Help

    Do you have the formula for computing percent now? How did you get 75% for those numbers? What is the formula?

     if (occupancyRate==50 && occupancyRate==74)
    When would this statement be true? For what values?

    You need to look at your code and see if it does what you intend.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    Oct 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Project Nursing Home Due Tonight Help

    So your saying number of occupied rooms / number rooms shoupdnt give you .75.
    20/15 is .75 im Not Concerned With Having It Print As A Percentage.


    My Instructions Were To Print Average Occupancy Rate If Between 50 and 74 thats Were Im Getting The If Statement From.

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Project Nursing Home Due Tonight Help

    Instructions Were To Print Average Occupancy Rate If Between 50 and 74
    Look at that statement again. What is it testing?
    Use English to describe how to test if a number is between 50 and 74. What two comparisons would need to be made.

    20/15 is .75
    Do you have a calculator? What is 20 divided by 15? It is NOT .75
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Using FOR and WHILE loops to find average (DUE TONIGHT)
    By cbh793 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: March 1st, 2013, 08:56 PM
  2. Replies: 1
    Last Post: December 5th, 2012, 10:58 PM
  3. Final Project Help Please? Due Tomorrow.
    By tylerreece22 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: April 23rd, 2012, 08:32 AM
  4. Have a C++ project due soon and am not sure if I'm using pointers right.
    By javapenguin in forum Other Programming Languages
    Replies: 12
    Last Post: September 19th, 2011, 09:54 PM
  5. Help On Java Homework (DUE TONIGHT!!!)
    By agmolina90 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 14th, 2011, 08:28 AM