In: Computer Science
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 60%
For the Overall Occupancy Rate, using the above example,
18/(8*30)=0.075 or 7.5%
Another example for Overall Occupancy Rate:
If 1st floor, 18 rooms occupied.
2nd floor, 30 rooms occupied, then the calculation is:
(18+30) /(8*30) or (18+30)/240 =0.2 or 20%
You will need to use Name Constants for Rooms (30 rooms), and Floors (8 floors).
Some variables and Constants you will need to declare in class level to do the Overall Total and Overall Occupancy Rate calculation.
Some variables you will need to use in the local level.
The application’s form should appear similar to the one shown below.
In the form load event handler, use a loop to populate floor 1 to 8 in combo box. (Do NOT create floor 1 to 8 at design time using the Items property)
On startup, “Select the floor” combo box should default to floor 1. Each time the user enters the occupancy for a single floor and clicks the Save button, the floor number in the Drop-Down List ComboBox should increment automatically (just add 1 to its SelectedIndex property), and a new line should appear in the ListBox with the percentage occupancy. Also, the contents of the TextBox at the top of the form should clear automatically when the user clicks the Save button, so the user does not accidentally enter the same data twice in a row.
The Restart button should clear all the appropriate controls on the form. “Select the floor” combo box should default to floor 1.
The Exit button should end the application.
The Save button should do all input validation and all other calculations. (Do NOT use a loop in the btnSave_click event handler)
Input Validation: Be sure to check for a non-integer value in TextBox using the Integer.TryParse method and notify the user if there is an error. Since each floor has only 30 rooms, you need to do the range check to prevent user enter a value is greater than 30 or a negative number. A zero is allowed to input since it may have no occupancy for the whole floor.
Use the values below to confirm that your application is performing the correct calculations.
Use access key for all buttons’ control.
Below is the solution:
Public Class frmMain
    Private Sub frmMain_Load(sender As Object, e As
EventArgs) Handles MyBase.Load
        txtRate.Enabled = False
'disable the textbox to enter the data on form load
        txtRooms.Enabled = False
'disable the textbox to enter the data on form load
        cmbFloor.Enabled = False
'disable the combobox
        cmbFloor.Text = 1
''first time set the text to 1
        For n = 1 To 8 'add the
combox value using for loop
           
cmbFloor.Items.Add(n)
        Next
    End Sub
    Dim Floor As Integer = 1 ''set the floor to
1
    Dim occupancy As
Integer         ' Occupancy
count
    Dim occupancySum As Integer = 0 ' Total
Occupancy count
    Private Sub btnComplete_Click(sender As Object,
e As EventArgs) Handles btnComplete.Click
        'This calculates and
displays each floors occupancy rate.
        Const maximumFloors As
Integer = 8 ''declare the number of floor
        Const maximumRooms As
Integer = 30 ''set the floor of each room to 30
        If Floor <= 8 Then
''Check for the 8 floor not more than 8 entry
           
If Not Integer.TryParse(txtNoOfRooms.Text, occupancy) Then ''check
for the integer input
               
MessageBox.Show("Enter Number of Rooms Integer only ")
           
ElseIf occupancy > 30 Or occupancy < 0 Then ''check for the
textbox of room entry must be 0-30
               
MessageBox.Show("Enter Number of Rooms 1 to 30 only ")
           
Else
               
occupancySum += occupancy ''sum of entered room for each
floor
               
ListBox1.Items.Add("Floor: " & Floor & " Rooms Occupied: "
& occupancy & " Occupancy Rate: " &
Math.Round((occupancy / maximumRooms) * 100, 2) & "%") 'display
the each room occupancy to the listbox
               
If Floor <= 8 Then ''check for the floor less that or equal
8
                   
cmbFloor.Text = Floor + 1
                   
Floor += 1
               
End If
               
If Floor = 9 Then ''check if the floor value has 9 then show the
combobx to 8
                   
cmbFloor.Text = 8
               
End If
               
txtRooms.Text = occupancySum.ToString ''display the rooms textbox
occupancy
               
txtRate.Text = Math.Round((occupancySum / (maximumRooms *
maximumFloors)) * 100, 2).ToString ''
               
txtNoOfRooms.Text = "" 'set the textbox room to empty
           
End If
        Else
           
MsgBox("Total floor is calculated Please Reset for new.")
        End If
        txtNoOfRooms.Select()
'focus the textbox room
End Sub
    Private Sub btnClear_Click(sender As Object,
e As EventArgs) Handles btnClear.Click
        'This procedure clears
all labels and list box.
        occupancySum = 0 ''rest
the occupancy sum of each floor rooms
        txtNoOfRooms.Text = ""
''set the textbox of the room to empty
        txtRate.Text = "" ''set
the rate to empty
        txtRooms.Text = "" ''set
the rooms to empty
        txtNoOfRooms.Select()
'focus on room textbox
        Floor = 1 'set the floor
to 1
        cmbFloor.Text = 1 'set
the combobox to 1
        ListBox1.Items.Clear()
''çlear the listbox
        ListBox1.Text =
String.Empty 'set the listbox string to empty
    End Sub
    Private Sub btnExit_Click(sender As Object, e
As EventArgs) Handles btnExit.Click
        Me.Close() '"close the
application
    End Sub
End Class
sample output:

