I\'m needing some help with this C# program. I\'m having trouble incorporating t
ID: 3596191 • Letter: I
Question
I'm needing some help with this C# program. I'm having trouble incorporating the necessary changes. The instructions and current code are below.
The program enables students to register for courses in a term of study. Students select
from a menu of courses for which they wish to register.
-The assumptions used by the program are:
Each course carries three credit hours.
The program terminates only when the student requires it.
-The program must follow these registration business rules:
No registration more than once for the same course.
No registration for more than nine credit hours (e.g., no more than three courses).
The program validates the user menu selection, and if valid, registers the student for the selected course. Otherwise, the program outputs an error message. The program then outputs the current list of registered classes. Additionally, the program should output the cumulative total credit hours the student has registered for thus far. You have been hired to complete the source code of this program by creating additional C# code in the button_Click() event hander according to these requirements:
Validate the user selection against the above business rules.
Output an error or a registration confirmation message based on your validation of user selection.
Update the total credit hours textbox if a registration is confirmed for a selected course.
Create additional (source) code.
A. Add required user interface components.
1. Code Variables: Code the required user interface (UI) variables ensuring that variables are defined with proper conventions. 2. Boolean Logic: Implement Boolean statements using proper Boolean logic. 3. Map User Input: Collect appropriate user input and map it properly to branching operations. 4. Create UI Code: Create user interface (UI) code as required.
B. Implement the required mathematical component. 1. Program Math Variables: Code the required math variables ensuring tha t variables are defined with proper conventions. 2. Program Math Operations: Program the required math operations with no syntax or computation errors. 3. Program Math Methods: Create the method(s) required to support the mathematical component.
C. Implement the library component as described in the software requirements. 1. Create Variables: Create additional variables and associated C# code to support the software requirements, ensuring the variables are defined with proper conventions. 2. Add Branching: Add additional branching code to support flow control. 3. Program Library Component: Program the required math operations related to the library component. 4. Incorporate Logic Operators: Incorporate the required logic operators to support the library component.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WPFRegisterStudent
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
Course choice;
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Course course1 = new Course("IT 145");
Course course2 = new Course("IT 200");
Course course3 = new Course("IT 201");
Course course4 = new Course("IT 270");
Course course5 = new Course("IT 315");
Course course6 = new Course("IT 328");
Course course7 = new Course("IT 330");
this.comboBox.Items.Add(course1);
this.comboBox.Items.Add(course2);
this.comboBox.Items.Add(course3);
this.comboBox.Items.Add(course4);
this.comboBox.Items.Add(course5);
this.comboBox.Items.Add(course6);
this.comboBox.Items.Add(course7);
this.textBox.Text = "";
}
private void button_Click(object sender, RoutedEventArgs e)
{
choice = (Course)(this.comboBox.SelectedItem);
this.listBox.Items.Add(choice);
// TO DO - Create code to validate user selection (the choice object)
// and to display an error or a registation confirmation message accordinlgy
// Also update the total credit hours textbox if registration is confirmed for a selected course
}
namespace WPFRegisterStudent
{
class Course
{
private string name = "";
private bool isRegisteredAlready = false;
public Course(string name)
{
this.name = name;
}
public void setName(string name)
{
this.name = name;
}
public string getName()
{
return name;
}
public bool IsRegisteredAlready()
{
return isRegisteredAlready;
}
public void SetToRegistered()
{
isRegisteredAlready = true;
}
public override string ToString()
{
return getName();
}
}
}
//XAML
<Window x:Class="WPFRegisterStudent.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WPFRegisterStudent"
mc:Ignorable="d"
Title="WPF Register Student " Height="395.902" Width="525" Loaded="Window_Loaded">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="232*"/>
<ColumnDefinition Width="285*"/>
</Grid.ColumnDefinitions>
<ComboBox x:Name="comboBox" HorizontalAlignment="Left" Margin="66,37,0,0" VerticalAlignment="Top" Width="164" IsDropDownOpen="True"/>
<Button x:Name="button" Content="Register for this course" HorizontalAlignment="Left" Margin="51.423,39,0,0" VerticalAlignment="Top" Width="166" Click="button_Click" Grid.Column="1"/>
<ListBox x:Name="listBox" HorizontalAlignment="Left" Height="69" Margin="66,276,0,0" VerticalAlignment="Top" Width="164"/>
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="51.423,276,0,0" TextWrapping="Wrap" Text="0" VerticalAlignment="Top" Width="73" IsReadOnly="True" Grid.Column="1"/>
<Label x:Name="label" Content="Please select a course for which you want to register" HorizontalAlignment="Left" Margin="66,7,0,0" VerticalAlignment="Top" Width="383" Grid.ColumnSpan="2"/>
<Label x:Name="label1" Content="You are currently registered for:" HorizontalAlignment="Left" Margin="66,245,0,0" VerticalAlignment="Top" Width="176" Grid.ColumnSpan="2"/>
<Label x:Name="label2" Content="Total Credit Hours" HorizontalAlignment="Left" Margin="51.423,245,0,0" VerticalAlignment="Top" Width="106" Grid.Column="1"/>
<Label x:Name="label3" Content="" HorizontalAlignment="Left" Margin="66,213,0,0" VerticalAlignment="Top" Width="383" Foreground="#FFEE0E0E" Grid.ColumnSpan="2"/>
</Grid>
</Window>
Explanation / Answer
MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WPFRegisterStudent
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
Course choice;
int TotalCreditHours = 0; //Used to increment how many credit hours have been registered
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Course course1 = new Course("IT 145");
Course course2 = new Course("IT 200");
Course course3 = new Course("IT 201");
Course course4 = new Course("IT 270");
Course course5 = new Course("IT 315");
Course course6 = new Course("IT 328");
Course course7 = new Course("IT 330");
this.comboBox.Items.Add(course1);
this.comboBox.Items.Add(course2);
this.comboBox.Items.Add(course3);
this.comboBox.Items.Add(course4);
this.comboBox.Items.Add(course5);
this.comboBox.Items.Add(course6);
this.comboBox.Items.Add(course7);
this.textBox.Text = "";
}
private void button_Click(object sender, RoutedEventArgs e)
{
choice = (Course)(this.comboBox.SelectedItem);
string courseName = choice.ToString();
switch (validateUserSelection(choice))
{
case 0://Display error confirmation: Already registered
label3.Content = "You have already registered for this course " + courseName;
break;
case 1: //Display error confirmation: Too many credit hours
label3.Content = "You cannot register for more than 9 credit hours.";
break;
case 2:
choice.SetToRegistered(); //Sets registration bool to true (See ValidateUserSelection function)
listBox.Items.Add(choice); // Display a registration confirmation message
label3.Content = "Registration confirmed for course " + courseName;
TotalCreditHours += 3; // update the total credit hours textbox if registration is confirmed for a selected course
textBox.Text = TotalCreditHours.ToString();
break;
}
}
private int validateUserSelection(Course selectedCourse) //Create code to validate user selection (the choice object)
{
if (selectedCourse.IsRegisteredAlready()) //Checks to see if course is already registered
{
return 0;
}
else if (TotalCreditHours > 8) //Checks to see if exceeded 8/ reached 9 credit hours
{
return 1;
}
return 2;
}
}
}
Course.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WPFRegisterStudent
{
class Course
{
private string name = "";
private bool isRegisteredAlready = false;
public Course(string name)
{
this.name = name;
}
public void setName(string name)
{
this.name = name;
}
public string getName()
{
return name;
}
public bool IsRegisteredAlready()
{
return isRegisteredAlready;
}
public void SetToRegistered()
{
isRegisteredAlready = true;
}
public override string ToString()
{
return getName();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.