Question
Each course carries three credit hours. The program terminates only when the student requires it. AFTER EACH REGISTRATION ASK THE USER IF HE/SHE WANTS TO
Each course carries three credit hours.
The program terminates only when the student requires it. AFTER EACH REGISTRATION ASK THE USER IF HE/SHE WANTS TO CONTINUE OR EXIT THE PROGRAM.
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.
Here is the code below:
This is an added class called Course to the WPF application.
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(); } } }
Here is the design of the window code:
Here is the mainwindow code:
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 { ///
/// Interaction logic for MainWindow.xaml ///
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);
// 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
}
} }
OUTPUT ***(Please note that the option asking the user to register for another course or exit the program needs to be an option in the final product even though it is not shown below!!)***
Dropdown menu to select classes:
After the user selects the class and clicks the register button:
User CANNOT register for the same class twice:
After the user selects 3 courses a 4th course CANNOT be registered:
Please select a course for which you want to register Register for this co urse You are currently registered for: Total Credit Hours
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started