In: Computer Science
Please complete in C# and use radio buttons on the form for the selections. Thank you!
For this assignment, you will be creating a Dorm and Meal Plan Calculator.
A university has the following dormitories: Allen Hall $1,500 per semester Pike Hall $1,600 per semester Farthing Hall $1,800 per semester University Suites $2,500 per semester The university also offers the following meal plans: 7 meals per week $ 600 per semester 14 meals per week $1,200 per semester Unlimited meals $1,700 per semester Create a multi-form Windows Forms Application with two forms.
The main form should allow the user to select a dormitory and a meal plan. The application should show the total charges on the second form.
Solution:
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
//store the dorm and
meal fees in array to calculate
int[] dormFees = { 1500,
1600, 1800, 2500 };
int[] mealFees = { 600,
1200, 1700 };
public Form1()
{
InitializeComponent();
}
private void
Form1_Load(object sender, EventArgs e)
{
//set the initial index of the combo boxes to 0 when form first
loads
comboBox1.SelectedIndex = 0;
comboBox2.SelectedIndex = 0;
}
//when calculate button
is clicked this event is called
private void
button1_Click(object sender, EventArgs e)
{
//selects the choice from the comboboxes and adds the total using
fees arrays declared before
int totalFees = dormFees[comboBox1.SelectedIndex] +
mealFees[comboBox2.SelectedIndex];
Form2 f2 = new Form2(totalFees); //initilise a new form2 class to
display the total
f2.Show();
}
}
}
Form1(design):
Form2.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
int totalFees;
public Form2(int
totalFees)
{
this.totalFees = totalFees;
InitializeComponent();
label1.Text = totalFees.ToString("C"); //displays the total in a
label with currency
}
private void
button1_Click(object sender, EventArgs e)
{
this.Close(); //closes form2
}
}
}
Form2(design):
Output: