83.2k views
4 votes
5. Dorm and Meal Plan Calculator (Page 494 ) Make sure to follow ALL instructions for this project which specifically asks you to create a module and two forms. The book shows you the forms in Figure 776 and Figure 7-77 5. Dorm and Meal Plan Calculator Suppose a university has the following dormitories, offered at these prices: - Allen Hall \$2,500 per semester - Pike Hall \$2, 200 per semester - Farthing Hall $2,100 per semester - University Suites $2,800 per semester I et us also assume the university also otters these meal plans: - 7 meals per week \$1,560 per semester - 14 meals per week $2,095 per semester - Unlimited meals \$2,500 per semester the slarlup form. constants to be displayed correctly in the list boxes.

User Millhorn
by
7.6k points

2 Answers

4 votes

Final answer:

The Dorm and Meal Plan Calculator project involves creating a module and two forms to calculate the costs of dormitories and meal plans at a university. The calculator allows the user to select a dormitory and meal plan, and calculates the total cost based on their choices.

Step-by-step explanation:

The Dorm and Meal Plan Calculator project involves creating a module and two forms to calculate the costs of dormitories and meal plans at a university. The dormitories are Allen Hall ($2,500 per semester), Pike Hall ($2,200 per semester), Farthing Hall ($2,100 per semester), and University Suites ($2,800 per semester). The meal plans are 7 meals per week ($1,560 per semester), 14 meals per week ($2,095 per semester), and Unlimited meals ($2,500 per semester).

To create the calculator, you will need to design a form to display the available dormitories and meal plans, and allow the user to select their choices. The module will contain the logic to calculate the total cost based on the user's selections. You can use list boxes to display the dormitory and meal plan options, and use constants to ensure the prices are displayed correctly.

User Sandor Davidhazi
by
7.7k points
3 votes

Below is a Python code for the Dorm and Meal Plan Calculator application:

# Module to hold the defined constants for the dormitories and meal plans

MODULE DormMealPlanConstants:

# Dormitory prices

DormitoryPrices = {

'Allen Hall': 2500,

'Pike Hall': 2200,

'Farthing Hall': 2100,

'University Suites': 2800

}

# Meal plan prices

MealPlanPrices = {

'7 meals per week': 1560,

'14 meals per week': 2095,

'Unlimited meals': 2500

}

# Startup form

FORM DormMealPlanForm:

# Controls

DormitoryComboBox: ComboBoxControl

MealPlanComboBox: ComboBoxControl

ChargesLabel: LabelControl

TotalChargesLabel: LabelControl

AddDormitoryButton: ButtonControl

ViewMealPlansButton: ButtonControl

ClearButton: ButtonControl

StatusBarControl: StatusBarControl

# Form events

Form_Load(Sender: Object, e: EventArgs):

# Initialize the dormitory combo box

for dormitory in DormMealPlanConstants.DormitoryPrices.keys():

DormitoryComboBox.Items.Add(dormitory)

DormitoryComboBox.SelectedIndex = 0

DormitoryComboBox_SelectedIndexChanged(Sender: Object, e: EventArgs):

UpdateCharges()

MealPlanComboBox_SelectedIndexChanged(Sender: Object, e: EventArgs):

UpdateCharges()

AddDormitoryButton_Click(Sender: Object, e: EventArgs):

# Add the selected dormitory to the status bar

StatusBarControl.Panels[0].Text = f"Dormitory: {DormitoryComboBox.Text}"

ViewMealPlansButton_Click(Sender: Object, e: EventArgs):

# Show the meal plans form

MealPlansForm.Show()

ClearButton_Click(Sender: Object, e: EventArgs):

# Clear all selections

DormitoryComboBox.SelectedIndex = -1

MealPlanComboBox.SelectedIndex = -1

ChargesLabel.Text = ""

TotalChargesLabel.Text = ""

UpdateCharges():

# Get the selected dormitory and meal plan

selectedDormitory = DormitoryComboBox.Text

selectedMealPlan = MealPlanComboBox.Text

# Calculate the charges

dormitoryCharge = DormMealPlanConstants.DormitoryPrices[selectedDormitory]

mealPlanCharge = DormMealPlanConstants.MealPlanPrices[selectedMealPlan]

totalCharges = dormitoryCharge + mealPlanCharge

# Display the charges

ChargesLabel.Text = f"{dormitoryCharge:.2f}"

TotalChargesLabel.Text = f"Total: {totalCharges:.2f}"

# Meal plans form

FORM MealPlansForm:

# Controls

MealPlanListBox: ListBoxControl

CloseButton: ButtonControl

# Form events

Form_Load(Sender: Object, e: EventArgs):

# Initialize the meal plan list box

for mealPlan in DormMealPlanConstants.MealPlanPrices.keys():

MealPlanListBox.Items.Add(mealPlan)

CloseButton_Click(Sender: Object, e: EventArgs):

# Close the form

Close()

# Run the application

Application.Run(DormMealPlanForm)

So, the code above is seen as a module that helps to defines two dictionaries: DormitoryPrices and MealPlanPrices. These dictionaries store the prices for the dormitories and meal plans, respectively.

Hence, The keys of the dictionaries are the names of the dormitories or meal plans, and the values are their corresponding prices.

See text below

. Dorm and Meal Plan Calculator Suppose a university has the following dormitories, offered at these prices: . Allen Hall $2,500 per semester . Pike Hall $2,200 per semester . Farthing Hall $2,100 per semester . University Suites $2,800 per semester Let us also assume the university also offers these meal plans: • 7 meals per week $1,560 per semester o 14 meals per week $2,095 per semester . Unlimited meals $2,500 per semester Create an application with a module and two forms. The module holds defined constants for the various dormitories and meal plans. The startup form holds the names of the dormitories, a set 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 buttons, shown in Figure 7-77. When the user selects a dormitory and meal plan, the application should show the total charges for the semester on the startup form Note: Use code statements in the Form Load event handler for each form to initialize 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 constants to be displayed correctly in the list boxes. Figure 7-76 Dorm and Meal Calculator—startup form be displayed correctly in the list boxes. Figure 7-76 Dorm and Meal Calculator—startup form Dorm and Meal Plan Calculator - EX Select a Dormitory Charges for the Semester Dormitory $2,200.00 Allen Hall- 2,500.00 Pike Hall - 2,200.00 Farthing Hall -2,100.00 University Suites - 2,800.00 Meal Plan $2,095.00 Total $4,295.00 Add Dormitory View Meal Plans Clear Ext Description Figure 7-77 Dorm and Meal Calculator—meal plans Meal Plans - OX Select a Weekly Meal Plan Add Meal Plan 7 Meals - 1,560.00 14 Meals - 2,095.00 Unlimited Meals - 2,500.00 Close

User Tarmelop
by
8.3k points

No related questions found