[Solved]C C Working Trying Get Display Number Credits Post Message Letting User Know Already Regis Q37126598
C# C#
I have been working on this trying to get it to display thenumber for the credits and to post a message letting the user knowthat they have already registered for a course and that they cannotchoose more than 9 credits when they try to choose more than 3classes.


This is the code in the 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;
private int totalCredits;//added this for the credits
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgse)
{
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);
ItemCollection courses = this.comboBox.Items;//set credits forcourse
foreach (Course course in courses)
{
course.SetCredits(3);
}
this.textBox.Text = “”;
}
private void button_Click(object sender, RoutedEventArgse)
{
choice = (Course)(this.comboBox.SelectedItem);
// TO DO – Create code to validate user selection (the choiceobject)
// and to display an error or a registation confirmation messageaccordinlgy
// Also update the total credit hours textbox if registration isconfirmed for a selected course
if (choice != null)
{
if (totalCredits == 9) // check whether it is completed the 9credit hours of the registered courses.
{
MessageBox.Show(“You can not register for more than 9 credithours.”, “Message”, MessageBoxButton.OK,MessageBoxImage.Warning);
}
else if (IsAlreadyRegisteredCourse(choice)) // check whether theselected course is already registered.
{
MessageBox.Show(“Already registerd. Please registered for anothercourse.”, “Message”, MessageBoxButton.OK,MessageBoxImage.Warning);
}
else
{
// add the registered course name to the listbox
this.listBox.Items.Add(choice.ToString());
// increase the total credits
totalCredits += choice.GetCredits();
}
}
else
{
MessageBox.Show(“Please choose a course to register.”, “Message”,MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
private bool IsAlreadyRegisteredCourse(Course choice) // checkwhether the choose cource is already registered.
{
bool registered = false;
ItemCollection registeredCourses = this.listBox.Items;
foreach (string course in registeredCourses)
{
if (course.Equals(choice.getName()))
{
registered = true;
break;
}
}
return registered;
}
}
}
this is how it’s supposed to look



Piopenes qister Studcnt Piaase salect a courss for which you war to registe App.coni You are currently regsored fer Total Credt Hours nina:xhetp://schemas.icrosoft.conywinfx/2202/m ealram».http://zchetu…psttealfutTiLa.urx,’.” reup wnutisility/2พ6. Title-y: Register Studert . Tencer’s Copy” Height-295,982. utst”-525″ Loaded-udo”-Lozded’s 沁ㄧ 見:Nunc-‘1.bc11° uu. Lent..Yu..r: urre, Lly registered rur.” hur using System; using System.Collections.Generic; using System.Linq using System.Text using System.Threading. Tasks: Search Solution Explorer (Ctrli+:) Solution ‘WPFRegisterStudent’ (1 project) 4. WPFRegisterStudent Properties с# Assemblyinfo.cs 6 namespace WPFRegisterStudent Resources.resx 8 D 0 Settings.settings 19 references class Course 9 10 References App.config App.xaml D App.xaml.cs private string name”; private bool isRegisteredAlready-false; private int credits; // number of credits of the course C# Course 7 references MainWindow.xaml ש MainWindow.xami.cs public Course(string name) 15 16 17 18 19 this.name name; 0 references public void setName (string name) 20 21 this.namename: 24 1 reference public int GetCredits() 25 26 27 28 29 return this.credits; 2 references public string getName() 30 32 return name; 1 reference public void SetCredits (int credits) 35 36 37 38 39 this.credits credits; 0 references public bool IsRegisteredAlreadyO 40 41 42 43 return isRegisteredAlready; O references public void SetToRegistered() 45 Solution Explorer Team Explorer Properties Course.cs File Properties isRegisteredAlready true; 47 48 49 1 reference public override string ToString() 50 Build Action Copy to Output Directory Custom Tool Custom Tool Namespace File Name Compile Do not copy return getName); 52 53 54 Course.cs Please select a course for which you want to register IT 145 Register for this course Registration Confirmed for course IT145.A You are currently registered for: IT 145 Total Credit Hours Please select a course for which you want to register IT 200 Register for this course You have already registerd for this IT 200 course. You are currently registered for: IT 145 IT 200 Total Credit Hours Please select a course for which you want to register IT 330 Register faxthis course You can not register for more than 9 credit hours. Total Credit Hours You are currently registered for: IT 145 IT 200 IT 315 Show transcribed image text Piopenes qister Studcnt Piaase salect a courss for which you war to registe App.coni You are currently regsored fer Total Credt Hours nina:xhetp://schemas.icrosoft.conywinfx/2202/m ealram».http://zchetu…psttealfutTiLa.urx,’.” reup wnutisility/2พ6. Title-y: Register Studert . Tencer’s Copy” Height-295,982. utst”-525″ Loaded-udo”-Lozded’s 沁ㄧ 見:Nunc-‘1.bc11° uu. Lent..Yu..r: urre, Lly registered rur.” hur
using System; using System.Collections.Generic; using System.Linq using System.Text using System.Threading. Tasks: Search Solution Explorer (Ctrli+:) Solution ‘WPFRegisterStudent’ (1 project) 4. WPFRegisterStudent Properties с# Assemblyinfo.cs 6 namespace WPFRegisterStudent Resources.resx 8 D 0 Settings.settings 19 references class Course 9 10 References App.config App.xaml D App.xaml.cs private string name”; private bool isRegisteredAlready-false; private int credits; // number of credits of the course C# Course 7 references MainWindow.xaml ש MainWindow.xami.cs public Course(string name) 15 16 17 18 19 this.name name; 0 references public void setName (string name) 20 21 this.namename: 24 1 reference public int GetCredits() 25 26 27 28 29 return this.credits; 2 references public string getName() 30 32 return name; 1 reference public void SetCredits (int credits) 35 36 37 38 39 this.credits credits; 0 references public bool IsRegisteredAlreadyO 40 41 42 43 return isRegisteredAlready; O references public void SetToRegistered() 45 Solution Explorer Team Explorer Properties Course.cs File Properties isRegisteredAlready true; 47 48 49 1 reference public override string ToString() 50 Build Action Copy to Output Directory Custom Tool Custom Tool Namespace File Name Compile Do not copy return getName); 52 53 54 Course.cs
Please select a course for which you want to register IT 145 Register for this course Registration Confirmed for course IT145.A You are currently registered for: IT 145 Total Credit Hours
Please select a course for which you want to register IT 200 Register for this course You have already registerd for this IT 200 course. You are currently registered for: IT 145 IT 200 Total Credit Hours
Please select a course for which you want to register IT 330 Register faxthis course You can not register for more than 9 credit hours. Total Credit Hours You are currently registered for: IT 145 IT 200 IT 315
Expert Answer
Answer to C# C# I have been working on this trying to get it to display the number for the credits and to post a message letting t… . . .
OR

