Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C# Exercise Create a collection class to manage students using the give Solution below. Your collection class should inherit from the collection base class. Extra

C# Exercise

Create a collection class to manage students using the give Solution below. Your collection class should inherit from the collection base class.

Extra Credit: 3 points

Create a procedures plan for your collection class.

image text in transcribed

image text in transcribed

StudentInfoFrom.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 Exercise7Solution { public partial class StudentInfoForm : Form { public StudentInfoForm() { InitializeComponent(); }

private void ClearForm() { txtFirstName.Focus(); txtFirstName.Clear(); txtLastName.Clear(); mtbSID.Clear(); mtbAcceptDate.Clear(); mtbAppDate.Clear(); txtCredits.Clear(); txtGPA.Clear(); errorProvider1.Clear(); }

private bool IsValidEntry() { bool answer = true; if (!Student.IsValidFirstName(txtFirstName.Text)) { answer = false; errorProvider1.SetError(txtFirstName, "First name is required"); }

if (!Student.IsValidLastName(txtLastName.Text)) { answer = false; errorProvider1.SetError(txtLastName, "Last name is required"); }

if (!Student.IsValidStudentID(mtbSID.Text)) { answer = false; errorProvider1.SetError(mtbSID, "Student ID is required, 9 digits"); } DateTime appDate; if (DateTime.TryParse(mtbAppDate.Text, out appDate)) { if (!Student.IsValidApplicationDate(appDate)) { answer = false; errorProvider1.SetError(mtbAppDate, "Application date is required, must be today or before"); } } else { answer = false; errorProvider1.SetError(mtbAppDate, "Application date is required, must be today or before"); } int credits; if (int.TryParse(txtCredits.Text, out credits)) { if (!Student.IsValidCredits(credits)) { answer = false; errorProvider1.SetError(txtCredits, "Credits is required, must be zero or more"); } } else { answer = false; errorProvider1.SetError(txtCredits, "Credits is required, must be zero or more"); } decimal gpa; if (decimal.TryParse(txtGPA.Text, out gpa)) { if (!Student.IsValidGPA(gpa)) { answer = false; errorProvider1.SetError(txtGPA, "GPA is required, must be zero or more"); } } else { answer = false; errorProvider1.SetError(txtGPA, "GPA is required, must be zero or more"); } return answer; }

private void btnAdd_Click(object sender, EventArgs e) { errorProvider1.Clear(); if (IsValidEntry()) { Student myStudent = new Student(txtFirstName.Text, txtLastName.Text, mtbSID.Text, DateTime.Parse(mtbAppDate.Text), int.Parse(txtCredits.Text), decimal.Parse(txtGPA.Text)); DateTime accept; if (DateTime.TryParse(mtbAcceptDate.Text, out accept)) myStudent.AcceptanceDate = accept; lstStudents.Items.Add(myStudent); } }

private void btnEdit_Click(object sender, EventArgs e) { errorProvider1.Clear(); int index = lstStudents.SelectedIndex; if (index != -1) { if (IsValidEntry()) { Student myStudent = new Student(txtFirstName.Text, txtLastName.Text, mtbSID.Text, DateTime.Parse(mtbAppDate.Text), int.Parse(txtCredits.Text), decimal.Parse(txtGPA.Text)); DateTime accept; if (DateTime.TryParse(mtbAcceptDate.Text, out accept)) myStudent.AcceptanceDate = accept; lstStudents.Items.RemoveAt(index); lstStudents.Items.Insert(index, myStudent); } } else { errorProvider1.SetError(lstStudents, "Select student, make entries, then click edit to update that student"); } }

private void btnClear_Click(object sender, EventArgs e) { ClearForm(); }

private void btnExit_Click(object sender, EventArgs e) { Close(); }

private void lstStudents_SelectedIndexChanged(object sender, EventArgs e) { errorProvider1.Clear(); } } }

StudentInfoForm.Designer.cs

namespace Exercise7Solution { partial class StudentInfoForm { ///

/// Required designer variable. /// private System.ComponentModel.IContainer components = null;

///

/// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); }

#region Windows Form Designer generated code

///

/// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.label1 = new System.Windows.Forms.Label(); this.txtFirstName = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.txtLastName = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.mtbAppDate = new System.Windows.Forms.MaskedTextBox(); this.label5 = new System.Windows.Forms.Label(); this.mtbAcceptDate = new System.Windows.Forms.MaskedTextBox(); this.label6 = new System.Windows.Forms.Label(); this.txtCredits = new System.Windows.Forms.TextBox(); this.label7 = new System.Windows.Forms.Label(); this.txtGPA = new System.Windows.Forms.TextBox(); this.lstStudents = new System.Windows.Forms.ListBox(); this.mtbSID = new System.Windows.Forms.MaskedTextBox(); this.btnAdd = new System.Windows.Forms.Button(); this.btnEdit = new System.Windows.Forms.Button(); this.btnClear = new System.Windows.Forms.Button(); this.btnExit = new System.Windows.Forms.Button(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.errorProvider1 = new System.Windows.Forms.ErrorProvider(this.components); ((System.ComponentModel.ISupportInitialize)(this.errorProvider1)).BeginInit(); this.SuspendLayout(); // // label1 // this.label1.Location = new System.Drawing.Point(27, 15); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(100, 23); this.label1.TabIndex = 0; this.label1.Text = "&First Name:"; this.label1.TextAlign = System.Drawing.ContentAlignment.TopRight; // // txtFirstName // this.txtFirstName.Location = new System.Drawing.Point(133, 12); this.txtFirstName.Name = "txtFirstName"; this.txtFirstName.Size = new System.Drawing.Size(100, 20); this.txtFirstName.TabIndex = 1; // // label2 // this.label2.Location = new System.Drawing.Point(27, 56); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(100, 23); this.label2.TabIndex = 2; this.label2.Text = "&Last Name:"; this.label2.TextAlign = System.Drawing.ContentAlignment.TopRight; // // txtLastName // this.txtLastName.Location = new System.Drawing.Point(133, 53); this.txtLastName.Name = "txtLastName"; this.txtLastName.Size = new System.Drawing.Size(100, 20); this.txtLastName.TabIndex = 3; // // label3 // this.label3.Location = new System.Drawing.Point(27, 97); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(100, 23); this.label3.TabIndex = 4; this.label3.Text = "Student &ID:"; this.label3.TextAlign = System.Drawing.ContentAlignment.TopRight; // // label4 // this.label4.Location = new System.Drawing.Point(27, 139); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(100, 23); this.label4.TabIndex = 6; this.label4.Text = "A&pplication Date:"; this.label4.TextAlign = System.Drawing.ContentAlignment.TopRight; // // mtbAppDate // this.mtbAppDate.Location = new System.Drawing.Point(133, 136); this.mtbAppDate.Mask = "00/00/0000"; this.mtbAppDate.Name = "mtbAppDate"; this.mtbAppDate.Size = new System.Drawing.Size(80, 20); this.mtbAppDate.TabIndex = 7; // // label5 // this.label5.Location = new System.Drawing.Point(27, 180); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(100, 23); this.label5.TabIndex = 8; this.label5.Text = "A&cceptance Date:"; this.label5.TextAlign = System.Drawing.ContentAlignment.TopRight; // // mtbAcceptDate // this.mtbAcceptDate.Location = new System.Drawing.Point(133, 177); this.mtbAcceptDate.Mask = "00/00/0000"; this.mtbAcceptDate.Name = "mtbAcceptDate"; this.mtbAcceptDate.Size = new System.Drawing.Size(80, 20); this.mtbAcceptDate.TabIndex = 9; // // label6 // this.label6.Location = new System.Drawing.Point(27, 221); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(100, 23); this.label6.TabIndex = 10; this.label6.Text = "&Credits:"; this.label6.TextAlign = System.Drawing.ContentAlignment.TopRight; // // txtCredits // this.txtCredits.Location = new System.Drawing.Point(133, 218); this.txtCredits.Name = "txtCredits"; this.txtCredits.Size = new System.Drawing.Size(46, 20); this.txtCredits.TabIndex = 11; // // label7 // this.label7.Location = new System.Drawing.Point(27, 262); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(100, 23); this.label7.TabIndex = 12; this.label7.Text = "&GPA:"; this.label7.TextAlign = System.Drawing.ContentAlignment.TopRight; // // txtGPA // this.txtGPA.Location = new System.Drawing.Point(133, 259); this.txtGPA.Name = "txtGPA"; this.txtGPA.Size = new System.Drawing.Size(46, 20); this.txtGPA.TabIndex = 13; // // lstStudents // this.lstStudents.FormattingEnabled = true; this.lstStudents.Location = new System.Drawing.Point(245, 13); this.lstStudents.Name = "lstStudents"; this.lstStudents.Size = new System.Drawing.Size(269, 264); this.lstStudents.TabIndex = 14; this.lstStudents.SelectedIndexChanged += new System.EventHandler(this.lstStudents_SelectedIndexChanged); // // mtbSID // this.mtbSID.Location = new System.Drawing.Point(133, 94); this.mtbSID.Mask = "000-00-0000"; this.mtbSID.Name = "mtbSID"; this.mtbSID.Size = new System.Drawing.Size(80, 20); this.mtbSID.TabIndex = 5; // // btnAdd // this.btnAdd.Location = new System.Drawing.Point(43, 315); this.btnAdd.Name = "btnAdd"; this.btnAdd.Size = new System.Drawing.Size(100, 23); this.btnAdd.TabIndex = 15; this.btnAdd.Text = "&Add"; this.toolTip1.SetToolTip(this.btnAdd, "Use current values as a new student entry"); this.btnAdd.UseVisualStyleBackColor = true; this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click); // // btnEdit // this.btnEdit.Location = new System.Drawing.Point(159, 315); this.btnEdit.Name = "btnEdit"; this.btnEdit.Size = new System.Drawing.Size(100, 23); this.btnEdit.TabIndex = 16; this.btnEdit.Text = "&Edit"; this.toolTip1.SetToolTip(this.btnEdit, "Use current values to update the currently selected student"); this.btnEdit.UseVisualStyleBackColor = true; this.btnEdit.Click += new System.EventHandler(this.btnEdit_Click); // // btnClear // this.btnClear.Location = new System.Drawing.Point(275, 315); this.btnClear.Name = "btnClear"; this.btnClear.Size = new System.Drawing.Size(100, 23); this.btnClear.TabIndex = 17; this.btnClear.Text = "Cl&ear"; this.toolTip1.SetToolTip(this.btnClear, "Clear for new entry"); this.btnClear.UseVisualStyleBackColor = true; this.btnClear.Click += new System.EventHandler(this.btnClear_Click); // // btnExit // this.btnExit.Location = new System.Drawing.Point(391, 315); this.btnExit.Name = "btnExit"; this.btnExit.Size = new System.Drawing.Size(100, 23); this.btnExit.TabIndex = 18; this.btnExit.Text = "E&xit"; this.toolTip1.SetToolTip(this.btnExit, "Close and exit app"); this.btnExit.UseVisualStyleBackColor = true; this.btnExit.Click += new System.EventHandler(this.btnExit_Click); // // errorProvider1 // this.errorProvider1.ContainerControl = this; // // StudentInfoForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(534, 351); this.Controls.Add(this.btnExit); this.Controls.Add(this.btnClear); this.Controls.Add(this.btnEdit); this.Controls.Add(this.btnAdd); this.Controls.Add(this.mtbSID); this.Controls.Add(this.lstStudents); this.Controls.Add(this.txtGPA); this.Controls.Add(this.label7); this.Controls.Add(this.txtCredits); this.Controls.Add(this.label6); this.Controls.Add(this.mtbAcceptDate); this.Controls.Add(this.label5); this.Controls.Add(this.mtbAppDate); this.Controls.Add(this.label4); this.Controls.Add(this.label3); this.Controls.Add(this.txtLastName); this.Controls.Add(this.label2); this.Controls.Add(this.txtFirstName); this.Controls.Add(this.label1); this.Name = "StudentInfoForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Student Info Exercise 7"; ((System.ComponentModel.ISupportInitialize)(this.errorProvider1)).EndInit(); this.ResumeLayout(false); this.PerformLayout();

}

#endregion

private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox txtFirstName; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox txtLastName; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label4; private System.Windows.Forms.MaskedTextBox mtbAppDate; private System.Windows.Forms.Label label5; private System.Windows.Forms.MaskedTextBox mtbAcceptDate; private System.Windows.Forms.Label label6; private System.Windows.Forms.TextBox txtCredits; private System.Windows.Forms.Label label7; private System.Windows.Forms.TextBox txtGPA; private System.Windows.Forms.ListBox lstStudents; private System.Windows.Forms.MaskedTextBox mtbSID; private System.Windows.Forms.Button btnAdd; private System.Windows.Forms.Button btnEdit; private System.Windows.Forms.Button btnClear; private System.Windows.Forms.Button btnExit; private System.Windows.Forms.ToolTip toolTip1; private System.Windows.Forms.ErrorProvider errorProvider1; } }

Program.cs

using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms;

namespace Exercise7Solution { static class Program { ///

/// The main entry point for the application. /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new StudentInfoForm()); } } }

Student.cs

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace Exercise7Solution {

public enum NameOrder { FirstLast, LastFirst}

public class Student { private string firstName, lastName, studentID; private DateTime applicationDate, acceptanceDate; private int credits; private decimal gpa;

public Student(string First, string Last, string SID, DateTime Application, int Credits, decimal Gpa) { this.FirstName = First; this.LastName = lastName; this.StudentID = SID; this.ApplicationDate = Application; this.Credits = Credits; this.GPA = Gpa; }

public Student(string First, string Last, string SID, DateTime Application, DateTime Accept, int Credits, decimal Gpa) { this.FirstName = First; this.LastName = lastName; this.StudentID = SID; this.ApplicationDate = Application; this.AcceptanceDate = Accept; this.Credits = Credits; this.GPA = Gpa; }

public string FirstName { get { return firstName; } set { if (IsValidFirstName(value)) firstName = value; else throw new ApplicationException("First name can't be empty"); } }

public string LastName { get { return lastName; } set { if (IsValidLastName(value)) lastName = value; else throw new ApplicationException("Last name can't be empty"); } }

public string StudentID { get { return studentID; } set { if (IsValidStudentID(value)) studentID = value; else throw new ApplicationException("Invalid Student ID must be 9 digits"); } }

public DateTime ApplicationDate { get { return applicationDate; } set { if (IsValidApplicationDate(value)) applicationDate = value; else throw new ApplicationException("Application date must be today or before"); } }

public DateTime AcceptanceDate { get { return acceptanceDate; } set { acceptanceDate = value; } }

public int Credits { get { return credits; } set { if (IsValidCredits(value)) credits = value; else throw new ApplicationException("Credits must be zero or more"); } }

public decimal GPA { get { return gpa; } set { if (IsValidGPA(value)) gpa = value; else throw new ApplicationException("GPA must be zero or more"); } }

public static bool IsValidFirstName(string value) { return !IsEmptyString(value); }

public static bool IsValidLastName(string value) { return !IsEmptyString(value); }

private static bool IsEmptyString(string value) { return value == ""; }

public static bool IsValidStudentID(string value) { bool answer = true; if (value.Length == 9) { foreach (char c in value) { if (!int.TryParse(c.ToString(), out int number)) { answer = false; break; } } } else { answer = false; } return answer; }

public static bool IsValidApplicationDate(DateTime value) { return value.Date == DateTime.Today; }

public static bool IsValidCredits(int value) { return value >= 0; }

public static bool IsValidGPA(decimal value) { return value >= 0; }

public string StudentName(NameOrder format) { string answer=""; switch (format) { case NameOrder.FirstLast: answer = string.Format("{0} {1}", FirstName, LastName); break; case NameOrder.LastFirst: answer = string.Format("{0}, {1}", LastName, FirstName); break; } return answer; }

public override string ToString() { return string.Format("{0} - {1}", StudentName(NameOrder.LastFirst), StudentID); } } }

Solution Explorer Search Solution Explorer (Ctrl+) -Solution Exercise7Solution' (1 project) Exercise7Solution Properties References App.config .; ClassDiagram1.cd DProgram.cS C Student.cs StudentlnfoForm.cs Student!nfoForm.Designer.cs StudentInfoForm.resx Solution Explorer Team Explorer Solution Explorer Search Solution Explorer (Ctrl+) -Solution Exercise7Solution' (1 project) Exercise7Solution Properties References App.config .; ClassDiagram1.cd DProgram.cS C Student.cs StudentlnfoForm.cs Student!nfoForm.Designer.cs StudentInfoForm.resx Solution Explorer Team Explorer

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions

Question

a sin(2x) x Let f(x)=2x+1 In(be)

Answered: 1 week ago

Question

Are there any disadvantages to this tactic?

Answered: 1 week ago

Question

Who is the assigned manager for each tactic?

Answered: 1 week ago