Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

VD Pearson eText CodeLab Web Based C O viewebookplus pearsoncrngcomebo values bo

ID: 3582907 • Letter: V

Question

VD Pearson eText CodeLab Web Based C O viewebookplus pearsoncrngcomebo values booklD:99334 platform:1113:fromloginpage:N:irwokelype unchState: guloEBook:platform:1113:global BooklD CM8/054885:userD 50331/2 st! PEARSON Welcu Bucks. Selling Sign ou My Searches 494 G VISUAL BASIC 494 Chapter 7 Multiple Forms, Modules, and Menus 5. Dorm and Meal Plan Calculator Suppose a university has the following dormitories, offered at these prices Allen Hall S2,500 per semester Table of Contents Pike Hal $2,200 per semcste Farthing Hall S2,100 per semester University Suite $2,800 per senmester and Visual Basi Let us also assume the university also offers these meal plans Chapter 2: creating 7 meals per week S1,560 per semester Applicatio with 14 meals per week $2,095 per semester Unlimited meals $2,500 per semester Chapter 4: Making Decisions Create an application with a module and two forms. The module holds defined con Chapter stants for the various dormitories and meal plans. The startup form holds the names of the dormitories, a ser of buttons, a status bar, and labels that display semester charges, as shown in Figure 7-76. A second form holds the list of meal plans, and selection bu Chapter 7: Multiple F tons, shown in Figure 7-77. When the user selects a dormitory and meal plan, the Cu y *rd More application should show the total charges for the semester on the startup form. Chaplnr 9 Fies, Printing, and n the Form Load event handler for ea Note: Use code h form to emel Chapter 10: Working with ize the list boxes with the names of the dormitories or meal plans, along with their prices. This must be done at runtime, to allow future changes in the values of price Chapter 11 Developing Web constants to be displayed correctly in the list boxes Figure 7-76 Dorm and Meal Calculator-startup form Copyright 16 Pearson Education, no. Allrights reserved Ribcy 8:21 AM 12/19/2016

Explanation / Answer

'We are assuming that the Main form name if MainForm1 and it contains the variables with given name for object as btnaddDrom, btnViewMealPlan, btnClear, lblDorm,lblFood,lblTotal, txtDorm, txtFoodPlan,txtTotal, btnexit and ListBox1

'We are assuming that the second form name is frmMealPlans and it contains following object with names ListBox2, btnaddMealPlan,btnClose

Public Class MainForm1

'Declaration of variable for Dormitary Cost, Food Cost and TotalAmount to be paid

Dim dormCost As Decimal = 0
Dim FoodCost As Decimal = 0
Dim Total As Decimal = 0


   'Main module execute when load the form or application
Private Sub MainForm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

   ' Declaration of constants to define the cost off Hall

Dim frmMainForm1 As New MainForm1
Dim AllenHall As Integer = 2500
Dim PikeHall As Integer = 2200
Dim FathingHall As Integer = 2100
Dim UniversitySuites As Integer = 2800

frmMainForm1.ShowDialog()
End Sub

'module which execute the code when Exit Button is clicked on the main form
'which closes the form

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
' Closes the forms
Me.Close()
End Sub

'Module which execute the code when user clicks on Clear Button of the form

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

   'Clear the Text Boxvalues to assign blank value
txtDormCost.Text = ""
txtMealPlan.Text = ""
txtTotal.Text = ""
End Sub


  
Private Sub btnaddMealPlan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
If ListBox1.SelectedIndex = -1 Then
MessageBox.Show("Select a meal plan", "Error")
End If
If ListBox1.SelectedIndex = 0 Then
txtDormCost.Text = AllenHall.ToString
   dormCost = AllenHall
ElseIf ListBox1.SelectedIndex = 1 Then
txtDormCost.Text = PikeHall.ToString
   dormCost = PikeHall
ElseIf ListBox1.SelectedIndex = 2 Then
txDormCost.Text = FathingHall.ToString
   dormCost = FathingHall
ElseIf ListBox1.SelectedIndex = 3 Then
txtDormCost.Text = UniversitySuites.ToString
   dormCost = UniversitySuites
End If
   'calculate Total Amount as dormCost+FoodCost
   Total= Total + DormCost
   txtTotal=Total.toString 'assignment of the Total Amount value to Total Text Field of Main Form
End Sub

Private Sub btnViewMealPlan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectMeal.Click
Dim frmMealPlans As New frmMealPlans
frmMealPlans.ShowDialog()
End Sub
End Class


'****************************************
'Food Plan Form When user Clicks on View Meal Plan Button
'it shows the frmMealPlans on the screen for the selection of Meal Plan


Public Class frmMealPlans

Private Property Results As Object
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
' Close the form.
Me.Close()
End Sub

Private Sub BtnAddMealPlan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEnter.Click
'Define constant to assign the cost of Food

   Dim Meals7 As Integer = 1560
Dim Meals14 As Integer = 2095
Dim Unlimited As Integer = 2500
Dim Results As Integer

If ListBox1.SelectedIndex = -1 Then
MessageBox.Show("Select at least one meal plan", "Error")
End If

If ListBox1.SelectedIndex = 0 Then
Results = Meals7
ElseIf ListBox1.SelectedIndex = 1 Then
Results = Meals14
ElseIf ListBox1.SelectedIndex = 2 Then
Results = Unlimited
End If

   'Calculate Total Amount as DormCost+FoodCost
   Total =Total + Result
   MainForm1.txtTotal = Total.toString 'Assigning the total Amount to be displayed on Main Forms Total Text Field
  
   'Close the current Form to return to main Form
   Me.close ()    

End Sub
End Class