Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.util.Scanner;
- //btw you need an if statement for your occupied rooms they can be more than rooms in total. GL & HF --verd
- public class HotelOccupancy {
- public static void main(String[] args) {
- int floor, rooms, occupiedRooms, totalRooms = 0, totalOccupiedRooms = 0;
- double occupancyRate;
- Scanner in = new Scanner(System.in);
- System.out.println("Enter the number of floors:");
- floor = in.nextInt();
- while (floor < 1) {
- System.out.println("The number of floors must be at least 1 or above.");
- System.out.println("Enter the number of floors:");
- floor = in.nextInt();
- }//changed here was: "{"
- for (int count = 1; count<= floor; count++) {
- System.out.println("Enter the number of rooms in a floor " +count+ ":");
- rooms = in.nextInt();
- while (rooms < 10) {
- System.out.println("The number of rooms must be at least 10 or above.");
- System.out.println("Enter the number of rooms in a floor " +count+ ":");
- rooms = in.nextInt();
- }
- System.out.println("Enter the number of occupied rooms in a floor " +count+ ":");
- occupiedRooms = in.nextInt();
- totalRooms = totalRooms + rooms;
- totalOccupiedRooms = totalOccupiedRooms + occupiedRooms;
- }
- System.out.println("Total number of rooms = "+totalRooms);
- System.out.println("Total number of occupied rooms = "+totalOccupiedRooms);
- System.out.println("Total number of vacant rooms = " +(totalRooms - totalOccupiedRooms));
- System.out.println("Total rate of occupancy = "+((double)totalOccupiedRooms/totalRooms));
- }
- //not his: "}"
- // not this: "}"
- }
Advertisement
Add Comment
Please, Sign In to add comment