Question

Write a complete Java program with methods that prompt user for the number of floors, rooms,...

Write a complete Java program with methods that prompt user for the number of floors, rooms, occupied rooms in a hotel. You must validate floors, rooms, occupied rooms. Compute vacant rooms, occupancy rate on each floor and display rooms, occupied rooms, vacant rooms and occupancy rate for each floor. Use the given method names. See validation rules below:

1. getFloors(). This method prompts user for number of floors in a hotel and returns floors to the caller.

2. testFloors(floors). Do not accept a value less than 1 for the number of floors. A loop should then iterate once for each floor. During each iteration, the loop prompts user for

3. getRooms(). Method prompts user for number of rooms on the floor and returns rooms.

4. testRooms(rooms) Do not accept a value less than 10.

5. getOccRooms(). Method prompts user for number of rooms that are occupied and returns occupied rooms.

6. testOccRooms(occRooms, rooms). Do not accept a value greater than the number of rooms on the floor.

7. computeVacRooms(rooms, occRooms) Calculate the number of vacant rooms on each floor and return vacant rooms.

8. computeOccRate(occRooms, rooms) Calculate the occupancy rate on each floor and return occupany rate. Occupancy rate = 100 * (double)rooms occupied / rooms on floor

9. display(rooms, occRooms, vacRooms, occRate) on each floor You may calculate totalRooms, totalOccRooms and totalVacRooms in the hotel inside the loop.

10. computeHotelOccRate(totalOccRooms, totalRooms)Calculate the occupancy rate for the hotel outside the loop. Hotel Occupancy Rate = 100 * (double)totalOccupiedRooms / totalRooms

11. display(totalRooms, totalOccRooms, totalVacRooms, hotelOccRate) for the hotel.

Output:

1. Rooms on each floor

2. Occupied rooms on each floor

3. Vacant rooms on each floor

4. Occupancy rate for each floor

5. Total number of rooms the hotel has

6. Total number of occupied rooms the hotel has

7. Total number of vacant rooms the hotel has

8. Occupancy rate for the hotel Note: 1-4 inside the loop; 5-8 outside the loop

Submit this printout and the following:

1. An algorithm

2. A complete Java Program (include comments/documentation in your program)

3. Output (see above)

Test Data Floors Rooms Occupied 1 10 8 2 15 12 3 20 25

Note: Invalid Occupied Rooms on floor 3.

Use valid number 18 to complete your program.

Using this as a guide line how would one make this program's layout ?

Essentially I have this :


import java.util.Scanner;

import java.text.DecimalFormat;

public class HotelFloors

{

public static void main(String[] args) {

int numFloor;

Scanner s = new Scanner(System.in);

DecimalFormat df = new DecimalFormat("#.##");

System.out.print("\nEnter number of floors, at least 1: ");

do{

numFloor = s.nextInt();

if(numFloor<1)

{

System.out.print("\nSorry there should be at least 1 floor, enter the number again: ");

}

}while(numFloor<1);

int totalRooms = 0;

int totalOccRoom = 0;

for(int i=1;i<=numFloor;i++)

{

int nRoom,occRoom;

if(i==13)

continue;

  

System.out.print("\nFloor "+i+" ");

System.out.print("\nPlease enter the number of rooms on the floor, at least 10: ");

do

{

nRoom = s.nextInt();

if(nRoom<10)

{

System.out.print("\nSorry there should be at least 10 rooms, enter the number again: ");

}

}while(nRoom<10);

  

totalRooms = totalRooms + nRoom;

  

System.out.print("\nPlease enter the number of rooms that are occupied on that floor: ");

do{

occRoom = s.nextInt();

if(occRoom>nRoom)

{

System.out.print("\nSorry occupancy number cannot be greater than total room, enter again: ");

}

}while(occRoom>nRoom);

  

double roomOccupancy = (double)occRoom/(double)nRoom;

  

totalOccRoom = totalOccRoom + occRoom;

  

System.out.print("\nFloor " + i +": " + nRoom +" rooms, "+ occRoom +" occupied. The occupancy rate for floor "+ i+ " is "+ df.format(roomOccupancy) +"\n");

}

double totalOccupancy = (double)totalOccRoom/(double)totalRooms;

System.out.print("\n\n****************************************");

System.out.print("\nAltogether,the hotel has " + totalRooms + " rooms,"+ totalOccRoom + " rooms are occupied, " + (totalRooms - totalOccRoom) +"rooms are vacant. The overall occupancy rate for the hotel is " + df.format(totalOccupancy));

}

}

How do I put this in a method format

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program Screen Shot:

Sample Output:

Program Code to Copy:

import java.util.Scanner;

import java.text.DecimalFormat;

public class HotelFloors{
      
       /**
       * Prompts user for number of floors in a hotel
       * @return number of floors
       */
   public static int getFloors(){
       int numFloor;
       Scanner s = new Scanner(System.in);
       System.out.print("\nEnter number of floors, at least 1: ");
       numFloor = s.nextInt();  
       numFloor = testFloors(numFloor);
       return numFloor;
   }  
  
   /**
   * Do not accept a value less than 1 for the number of floors.
   * @return number of floors
   */
   public static int testFloors(int floors){
   Scanner s = new Scanner(System.in);
   do{
   if(floors<1){
       System.out.print("\nSorry there should be at least 1 floor,"+
   " enter the number again: ");
       floors = s.nextInt();
   }
   }while(floors<1);
   return floors;
   }
  
   /**
   * prompts user for number of rooms on the floor
   * @return number of rooms
   */
   public static int getRooms(){
       Scanner s = new Scanner(System.in);
       int nRoom;
       System.out.print("\nPlease enter the number of rooms on the"+
       " floor, at least 10: ");
       nRoom = s.nextInt();
       nRoom = testRooms(nRoom);
       return nRoom;
   }
  
   /**
   * Do not accept a value less than 10
   * @return number of rooms
   */
   public static int testRooms(int rooms){
       Scanner s = new Scanner(System.in);
       do{
       if(rooms<10){
           System.out.print("\nSorry there should be at least 10 rooms,"+
       " enter the number again: ");
           rooms = s.nextInt();
       }
       }while(rooms<10);
       return rooms;
   }
   //
   /**
   * prompts user for number of rooms that are occupied.
   *@return number of occupied rooms
   */
   public static int getOccRooms(){
       Scanner s = new Scanner(System.in);
       int occRoom;
       System.out.print("\nPlease enter the number of rooms that"+
       " are occupied on that floor: ");
       occRoom = s.nextInt();
       return occRoom;
   }
   /**
   * Do not accept a value greater than the number of rooms on the floor
   * @param occRooms
   * @param rooms
   * @return
   */
   public static int testOccRooms(int occRooms, int rooms){
       Scanner s = new Scanner(System.in);
       do{
           if(occRooms>rooms){
               System.out.print("\nSorry occupancy number cannot be greater"+
           "than total room, enter again: ");
               occRooms = s.nextInt();
           }
  
       }while(occRooms>rooms);
       return occRooms;
   }
  
   /**
   * Calculate the number of vacant rooms on each floor and return .
   * @return vacant rooms
   */
   public static int computeVacRooms(int rooms, int occRooms){
       return rooms - occRooms; // vacant
   }
  
   /**
   * Calculate the occupancy rate on each floor
   * @return occupany rate
   */
   public static double computeOccRate(int occRooms, int rooms) {
       return 100 * (double)occRooms/(double)rooms;
   }
  
   /**
   *
   * @param rooms
   * @param occRooms
   * @param vacRooms
   * @param occRate
   */
   public static void display(int rooms, int occRooms,
           int vacRooms, double occRate){
       DecimalFormat df = new DecimalFormat("#.##");
       System.out.print(rooms +" rooms, "+ occRooms +
               " occupied. The occupancy rate for the floor is "+
               df.format(occRate) +"%\n");
  
   }
  
   /**
   *
   * @param totalOccRooms
   * @param totalRooms
   * @return HotelOccRate
   */
   public static double computeHotelOccRate(int totalOccRooms, int totalRooms){
       return 100 * (double)totalOccRooms/(double)totalRooms;
   }
  
   /**
   *
   * @param totalRooms
   * @param totalOccRooms
   * @param totalVacRooms
   * @param hotelOccRate
   */
   public static void displayy(int totalRooms, int totalOccRooms,
           int totalVacRooms, double hotelOccRate){
       DecimalFormat df = new DecimalFormat("#.##");
       System.out.print("\n\n****************************************");
       System.out.print("\nAltogether,the hotel has " + totalRooms +
               " rooms,"+ totalOccRooms +
               " rooms are occupied, " +totalVacRooms+
               " rooms are vacant. \nThe overall occupancy rate for the hotel is "+
               df.format(hotelOccRate) + "%");
  
   }
  
   public static void main(String[] args) {
       Scanner s = new Scanner(System.in);
       DecimalFormat df = new DecimalFormat("#.##");
       int numFloor = getFloors();
       int totalRooms = 0;
       int totalVacRooms =0;
       int nRoom,occRoom;
       int totalOccRoom = 0;
       int vacRooms;
       double occRate;
      
       for(int i=1;i<=numFloor;i++){
       if(i==13)
       continue;
      
       System.out.print("\nFloor "+i+" ");
       nRoom = getRooms();
       occRoom = getOccRooms();
       occRoom = testOccRooms(occRoom,nRoom);
       vacRooms = computeVacRooms(nRoom,occRoom);
       occRate = computeOccRate(occRoom,nRoom); // percent
       display(nRoom,occRoom,vacRooms,occRate);
       //
       totalRooms = totalRooms + nRoom;
       totalOccRoom = totalOccRoom + occRoom;
       totalVacRooms = totalVacRooms + vacRooms;
       }
       double totalOccupancy = computeHotelOccRate(totalOccRoom,totalRooms);
       displayy(totalRooms,totalOccRoom,totalVacRooms,totalOccupancy);
      
   }

}

------------------------------------------------------------------------------
COMMENT DOWN FOR ANY QUERY RELATED TO THIS ANSWER,

IF YOU'RE SATISFIED, GIVE A THUMBS UP
~yc~

Add a comment
Know the answer?
Add Answer to:
Write a complete Java program with methods that prompt user for the number of floors, rooms,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need to output Number of rooms : , Occupied rooms:, Vacant rooms:, and Occupancy rate:,...

    I need to output Number of rooms : , Occupied rooms:, Vacant rooms:, and Occupancy rate:, I've written the java program but I can not get the output I need. What am I doing wrong here? This is a java program and I'm not to use anything advanced, just beginner java programming. Any help would be appreciated import java.util.Scanner; // Needed for the Scanner class /** * This program will read in the number of floors the resort * contains...

  • C ++ Project Description The BlueMont chain hotels have 4 different types of room: Single room:...

    C ++ Project Description The BlueMont chain hotels have 4 different types of room: Single room: $60/night Double room: $75/night King room:   $100/night Suite room: $150/night The size of the hotel chains in different locations may be different in terms of the number of floors and the type and the number of rooms on each floor. You are required to write a program that calculates the occupancy rate and the total hotel income for one night and displays this information as...

  • **Use C++ ** Project Description The BlueMont chain hotels have 4 different types of room: Single...

    **Use C++ ** Project Description The BlueMont chain hotels have 4 different types of room: Single room: $60/night Double room: $75/night King room:   $100/night Suite room: $150/night The size of the hotel chains in different locations may be different in terms of the number of floors and the type and the number of rooms on each floor. You are required to write a program that calculates the occupancy rate and the total hotel income for one night and displays this...

  • java programe Write a program that prompts the user to enter in an integer number representing...

    java programe Write a program that prompts the user to enter in an integer number representing the number of elements in an integer array. Create the array and prompt the user to enter in values for each element using a for loop. When the array is full, display the following: The values in the array on a single line. The array with all of the elements reversed. The values from the array that have even numbered values. The values from...

  • Public Class Form1     Private Sub CompleteReport_Click(sender As Object, e As EventArgs) Handles CompleteReport.Click         Dim...

    Public Class Form1     Private Sub CompleteReport_Click(sender As Object, e As EventArgs) Handles CompleteReport.Click         Dim room As Double 'Assigns room as double         Dim rate As Double 'Assigns rate as double         Dim room2 As Double 'Assigns room as double         Dim overallRate As Double 'Assigns overall as double         Dim a As Integer 'Assign a as an integer         For a = 1 To 8 'Assign a as an 1 to 8 for all 8 floors             With...

  • Write a program that will predict the size of a population of organisms. The program should...

    Write a program that will predict the size of a population of organisms. The program should ask for the starting number of organisms, their average daily population increase (as a percentage), and the number of days they will multiply. For example, a population might begin with two organisms, have an average daily increase of 50 percent, and will be allowed to multiply for seven days. The program should use a loop to display the size of the population for each...

  • FRQ: Hotel Rooms A & B

    The management of a motel wishes to keep track of the occupancy of rooms in the motel. Each room is represented by an object of the following Room class.public class Room {   private int roomNumber;   private boolean occupied;   private String bookingName;       /** Attempts to check a new guest into the room. If the room is not occupied (the      * variable occupied is false), changes bookingName to name and sets     * occupied to true.     * Otherwise does not change the values of the member variables.     * @param name the name of the guest checking in as a String     * @return true if the check-in was successful and bookingName was changed     *  false otherwise     */   public boolean checkInNewGuest(String name)   {  /* implementation not shown */  }       /** @return the room number */   public int getNumber()   {  return roomNumber;  }   /** @return true if the room is occupied; false otherwise. */   public boolean isOccupied()   {  return occupied;  }     // There may be instance variables, constructors and methods that are not shown. }The following OccupancyInfo class creates and maintains a database of the rooms in the hotel. The rooms are not sorted in the database, but no two...

  • Program Requirements ·         The program prompts the user to enter a loan amount and an interest rate....

    Program Requirements ·         The program prompts the user to enter a loan amount and an interest rate. ·         The application calculates the interest amount and formats the loan amount, interest rate, and interest amount. Then, it displays the formatted results to the user. ·         The application prompts the user to continue. ·         The program stops prompting the user for values after taking 3 loan amounts. ·         The application calculates and displays the total loan and interest amount and ends the program Example Output Welcome to...

  • Write a Java program to meet the following requirements: 1. Prompt the user to enter three...

    Write a Java program to meet the following requirements: 1. Prompt the user to enter three strings by using nextLine(). Space can be part of the string). ( Note: your program requires using loop: for-loop, while-loop or do-while-loop to get the input String ) 2. Write a method with an input variable (string type).The method should return the number of lowercase letters of the input variable. 3. Get the number of the lowercase letters for each user input string by...

  • C++ Program Write a do-while loop that continues to prompt a user to enter a number...

    C++ Program Write a do-while loop that continues to prompt a user to enter a number less than 100, until the entered number is actually less than 100. End each prompt with a newline. Ex: For the user input 123, 395, 25, the expected output is: Enter a number (<100): Enter a number (<100): Enter a number (<100): Your number < 100 is: 25 #include <iostream> using namespace std; int main() { int userInput; /* Your solution goes here */...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT