Question

In: Computer Science

Write a program that calculates the occupancy rate for a hotel. The program should start by asking the user how many floors the hotel has.

Use JAVA

Program #1: Hotel Occupancy: Write a program that calculates the occupancy rate for a hotel. The program should start by asking the user how many floors the hotel has. A for loop should then iterate once for each floor. In each iteration of the for loop, the program should ask the user for the number of rooms of the floor and how many of them are occupied. After all of the iterations are complete the program should display how many rooms the hotel has, how many of them are occupied, and the percentage of rooms that are occupied.

It is traditional that most hotels do not have a 13thfloor. The for loop in this program should skip the entire thirteenth loop iteration.

Input validation: Do not accept a value of less than one for the number of floors. Do not accept a value of less than 10 for the number of rooms on a floor. Do not accept a value for occupied that is greater than rooms.

EXAMPLE INPUT TO USE FOR TESTING (just an example your program should work for all different inputs):

If the Number of Floors in the Hotel: 16

And the user to INPUT the following information for total rooms and occupied rooms:

Floor #

Total Rooms

Occupied Rooms

1

200

180

2

170

100

3

50

20

4

125

125

5

100

80

6

200

80

7

80

40

8

90

45

9

95

0

10

115

103

11

125

17

12

140

128

14

130

129

15

100

99

16

60

24

The output of your program for the above example should be (do NOT print the above chart!):

The Hotel has 1780 Total Rooms.

1170 of the Rooms are Occupied.

66 % of the Rooms are Occupied.

Program #2: Pennies: For the first day worked a person earns $1.00 for the entire day. For the second day worked the person’s daily pay is doubled to $2.00. For the third day worked the person’s daily pay is doubled again to $4.00. For each consecutive day a person works their daily pay is doubled in this way.

Write a program that asks a user to enter the number of days they worked and then calculates the pay they earned for each day along with the total pay they earned for all of the days.   The program output should be the pay for each day and the total pay earned for all the days.

Input Validation: Do not let the user enter a number of days that is less than 1. Use a loop to prompt them to enter another number for the number of days if they enter a number that is less than 1.

Make sure and format your output.

Example: This would be the output for a person who worked 4 days

Pay for Day 1: $1.00
Pay for Day 2: $2.00
Pay for Day 3: $4.00
Pay for Day 4: $8.00

TOTAL PAY FOR 4 DAYS: $15.00

Solutions

Expert Solution

1)Code - Main.java

import java.util.*;
public class Main
{
   public static void main(String[] args) {
   //variable declare
   int noOfFloors;
   //Scanner to read user input
   Scanner sc = new Scanner(System.in);
       System.out.println("Enter number of floors hotel has : ");
//get no of floors from user
       noOfFloors = sc.nextInt();
//number of floors check is greater then 1 or not
       while(noOfFloors<1){
       System.out.println("Enter number of floors hotel should be greater than 1 : ");
       noOfFloors = sc.nextInt();
       }
       //roomsPerFloor array and ocuupiedRoomsPerFloor array initialized
       int roomsPerFloor[] = new int[noOfFloors];
       int ocuupiedRoomsPerFloor[] = new int[noOfFloors];
       //use for loop to iterate
       for(int i = 0 ; i        //if the floor is 13 then skip
       if(i==12){
       roomsPerFloor[i] = 0;
       ocuupiedRoomsPerFloor[i]= 0;
       continue;
       }
       //enter number of room in floor
       System.out.println("Enter number of rooms on floor "+ (i+1)+":");
       roomsPerFloor[i] = sc.nextInt();
//check room are less then 10 then again ask to enter
       while(roomsPerFloor[i]<10){
       System.out.println("Enter number of rooms on floor "+ (i+1)+" greater than 10 :");
       roomsPerFloor[i] = sc.nextInt();
       }
       //ask again number of room occupied
       System.out.println("Enter number of occupied rooms on floor "+ (i+1)+":");
//store it
       ocuupiedRoomsPerFloor[i] = sc.nextInt();
      
       }
       //calculate total room and total occupied rooms
       int totalRooms=0,occupiedRooms = 0;
       for(int i = 0 ; i //sum up in array
       totalRooms+=roomsPerFloor[i];
       occupiedRooms+=ocuupiedRoomsPerFloor[i];
       }
       //print the details
       System.out.println("The hotel has "+totalRooms+" Total Rooms");
       System.out.println(occupiedRooms+" of Rooms are Occupied");
       float percOccupied = (float)occupiedRooms/totalRooms*100;
       System.out.println(percOccupied+"% of Rooms are Occupied");
   }
}

Screenshots -


Related Solutions

Hotel Occupancy C++ Only Program Description Write a program that calculates the occupancy rate for a...
Hotel Occupancy C++ Only Program Description Write a program that calculates the occupancy rate for a hotel. The program should read its data from a file named "hotel.dat". The first line of this file will be a single integer specifying the number of floors in the hotel. Each of the remaining (N) lines will have two integers; the number of rooms on that floor and the number of occupied rooms on that floor. Your program should display the following: How...
IN JAVA Write a program that calculates the occupancy rate for each floor of a hotel....
IN JAVA Write a program that calculates the occupancy rate for each floor of a hotel. (Use a sentinel value and please point out the sentinel in bold.) 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,...
Write a program that calculates the occupancy rate for each floor of a hotel. (Use a...
Write a program that calculates the occupancy rate for each floor of a hotel. (Use a sentinel value and please point out the sentinel in bold.) 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...
Using Loops for the Hotel Occupancy calculator. You will write a program that calculates the occupancy...
Using Loops for the Hotel Occupancy calculator. You will write a program that calculates the occupancy of a hotel. Rules: 1# The hotel must have more than 2 floors and less than or equal 5 floors. 2# Each floor in the hotel can have a different number of rooms on the floor. 3# You must set the number of occupied rooms. Again, there must less rooms occupied than the number of rooms. 4# Using the total number of rooms and...
Write a program that calculates the salary of employees. The program should prompt the user to...
Write a program that calculates the salary of employees. The program should prompt the user to enter hourly rate and number of hours of work a day. Then, the program should display the salary daily, bi-weekly (5 days a week), and monthly. Sample program: Enter your hourly rate: >>> 20 Enter how many hours you work a day: >>> 8 Your daily salary is: $160 Your bi-weekly salary is: $1600 Your monthly: $3200
Please use Visual Basic Hotel Occupancy The Hotel has 8 Floors and 30 rooms on each...
Please use Visual Basic Hotel Occupancy The Hotel has 8 Floors and 30 rooms on each floor. Create an application that calculates the occupancy rate for each floor, and the overall occupancy rate for the hotel. The occupancy rate is the percentage of rooms occupied, and may be calculated by dividing the number of rooms occupied by the number of rooms. For example, if 18 rooms on the 1st floor are occupied, the Occupancy Rate is as follows: 18/30=0.6 or...
Create a matlab program that calculates equivalent cpacitance and charge by asking the user whether the...
Create a matlab program that calculates equivalent cpacitance and charge by asking the user whether the circuit is in paraller , series or combination and then asks for the values of capacitances and voltage. After that it calculates the equivalent capacitance.
C Programming use notes Start by asking the user how many grades are to be entered....
C Programming use notes Start by asking the user how many grades are to be entered. Then ask for each one of theses grades. Calculate the average grade and the number of failing grades (grade less than 70). Display on the screen the average grade and the number of failing grades
Can you provide java code for a program that prompts the user by asking "How many...
Can you provide java code for a program that prompts the user by asking "How many one mile races have you ran?". After the user inputs how many one mile races have they run it then prompts the user to input how many seconds it took for them to finish each race. So for example, if the user ran 6 races then the user will have to input 6 race times. Is there a way when you prompt the user...
First, write a program to loop asking for a number from the user until the user...
First, write a program to loop asking for a number from the user until the user inputs a zero or until the user has input 50 numbers. Store each value in an array except the values that are divisible by 5 and display all stored values. Determine how many of the values stored in the array were divisible by 10 and display result. Next, write a function getMinMax that accepts an array of floats and the size of the array,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT