Floor Rooms Occupied Occupancy Rate Room Price 1 20 14 70.0% $ 168.99 2 33 18 54.5% $ 152.99 Revenue $ 2,365.86 $ 2,753.82 3 33 12 36.4% $ 152.99 $ 1,835.88 4 33 15 45.5% $ 152.99 10 5 16 8 50.0% $ 254.99 $ 2,294.85 $ 2,039.92

Programming with Microsoft Visual Basic 2017
8th Edition
ISBN:9781337102124
Author:Diane Zak
Publisher:Diane Zak
Chapter4: The Selection Structure
Section: Chapter Questions
Problem 1MQ6
icon
Related questions
Question

//Main.cpp

 

public class Main {
    public static void main(String[] args) {

        final int NUM_FLOORS = 5;
        Hotel[] floor_number = new Hotel[NUM_FLOORS];

        floor_number[0] = new Hotel(20, 14, 168.99); 
        floor_number[1] = new Hotel(33, 18, 152.99); 
        floor_number[2] = new Hotel(33, 12, 152.99); 
        floor_number[3] = new Hotel(33, 15, 152.99); 
        floor_number[4] = new Hotel(16,  8, 254.99);  

        System.out.printf("%-6s %-8s %-10s %-15s %-12s %-10s\n",
           "Floor", "Rooms", "Occupied", "Occupancy Rate", "Room Price", "Revenue");

        for (int i = 0; i < floor_number.length; i++) {
            Hotel current_hotel_number = floor_number[i];

            int rooms = current_hotel_number.getRooms();
            int occupiedRooms = current_hotel_number.getOccupiedRooms();
            double roomCost = current_hotel_number.getRoomCost();
            double occupancyRate = current_hotel_number.getFloorOccupancyRate();
            double revenue = current_hotel_number.getFloorRevenue();

            System.out.printf("%-6d", i + 1);                       
    System.out.printf("%-8d", rooms);                        
    System.out.printf("%-10d", occupiedRooms);               
    System.out.printf("%6.1f%%", occupancyRate);             
    System.out.printf("         $%-10.2f", roomCost);        
    System.out.printf("$%-10.2f\n", revenue);        
            }
    }
}

 

 

 

//Hotel.java

public class Hotel
{
private int rooms ;
private int occRooms ;
private double roomCost ;

public Hotel()
{
rooms = 0 ;
occRooms = 0 ;
roomCost = 0.0 ;
}

public Hotel(int rms, int occRms, double rmCst)
{
rooms = rms ;
occRooms = occRms ;
roomCost = rmCst ;
}

public Hotel(String rms, String occRms, String rmCst)
{
rooms = Integer.parseInt(rms) ;
occRooms = Integer.parseInt(occRms) ;
roomCost = Double.parseDouble(rmCst) ;
}

public void setRooms(int rms)
{
rooms = rms ;
}

public void setRooms(String rms)
{
rooms = Integer.parseInt(rms) ;
}

public void setOccupiedRooms(int occRms)
{
occRooms = occRms ;
}

public void setOccupiedRooms(String occRms)
{
occRooms = Integer.parseInt(occRms) ;
}

public void setRoomCost(double rmCst)
{
roomCost = rmCst ;
}

public void setRoomCost(String rmCst)
{
roomCost = Double.parseDouble(rmCst) ;
}

public int getRooms()
{
return rooms ;
}

public int getOccupiedRooms()
{
return occRooms ;
}

public double getRoomCost()
{
return roomCost ;
}

public double getFloorRevenue()
{
return occRooms * roomCost ;
}

public double getFloorOccupancyRate()
{
return ((double)occRooms / (double)rooms) * 100 ;
}
}

 

When I run and compile the 2 Java files above, the number 8 in the "Occupied" column does not align correctly under the "5". I tried different things to get it to align properly under the 5 but unfortunately none of them worked. Can someone please help me? I've attached the required format with the required correct output. 

Floor Rooms
Occupied
Occupancy Rate
Room Price
1
20
14
70.0%
$ 168.99
2
33
18
54.5%
$ 152.99
Revenue
$ 2,365.86
$ 2,753.82
3
33
12
36.4%
$ 152.99
$ 1,835.88
4
33
15
45.5%
$ 152.99
10
5
16
8
50.0%
$ 254.99
$ 2,294.85
$ 2,039.92
Transcribed Image Text:Floor Rooms Occupied Occupancy Rate Room Price 1 20 14 70.0% $ 168.99 2 33 18 54.5% $ 152.99 Revenue $ 2,365.86 $ 2,753.82 3 33 12 36.4% $ 152.99 $ 1,835.88 4 33 15 45.5% $ 152.99 10 5 16 8 50.0% $ 254.99 $ 2,294.85 $ 2,039.92
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781305627482
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781285196145
Author:
Steven, Steven Morris, Carlos Coronel, Carlos, Coronel, Carlos; Morris, Carlos Coronel and Steven Morris, Carlos Coronel; Steven Morris, Steven Morris; Carlos Coronel
Publisher:
Cengage Learning