Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 2 requires utilizing your new knowledge of the windows form controls that we learned about in Chapter 10 as well as the debugging techniques

Assignment 2 requires utilizing your new knowledge of the windows form controls that we learned about in Chapter 10 as well as the debugging techniques we learned in Chapter 11. Youll download an existing solution that has some bugs. Youll need to identify and resolve the problems that are noted below and answer the associated questions. Once youve fixed the problems answer the questions in a word document and zip the solution files and the word document. Name the zip file, Assignment2_[YOURNAME] and submit to blackboard under assignment 2. Part 1 - Correct the follow problems: 1. After the application starts, there are no items in the combo box that allows the user to choose a major. 2. Every time a student is registered, the text student name appears in the listbox instead of the name that the user entered. 3. The student level radio buttons arent working as expected. When a user chooses Freshman, Sophomore or Junior the text Senior appears in the listbox. However, when a user chooses the Senior option, the text Freshman appears in the listbox. Part 2 - Answer the following questions: 1. Before you fixed the code, why werent there any items in the major combo box? 2. Before you fixed the code, why was the text student name always shown regardless of what the user entered in the name textbox? 3. Before you fixed the code, why was the text Senior always appearing in the list box when you selected the Freshman, Sophomore, or Junior options, but the text Freshman appeared when the user chose the Senior option?

namespace Assignment2 { partial class Form1 { ///

/// 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.label1 = new System.Windows.Forms.Label(); this.txtName = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.cbMajor = new System.Windows.Forms.ComboBox(); this.rdoFreshman = new System.Windows.Forms.RadioButton(); this.rdoSophmore = new System.Windows.Forms.RadioButton(); this.rdoJunior = new System.Windows.Forms.RadioButton(); this.rdoSenior = new System.Windows.Forms.RadioButton(); this.chkFirstTimeStudent = new System.Windows.Forms.CheckBox(); this.btnRegister = new System.Windows.Forms.Button(); this.lstRegisterStudents = new System.Windows.Forms.ListBox(); this.grpBoxLevel = new System.Windows.Forms.GroupBox(); this.grpBoxLevel.SuspendLayout(); this.SuspendLayout(); // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(13, 41); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(68, 25); this.label1.TabIndex = 0; this.label1.Text = "Name"; // // txtName // this.txtName.Location = new System.Drawing.Point(97, 35); this.txtName.Name = "txtName"; this.txtName.Size = new System.Drawing.Size(230, 31); this.txtName.TabIndex = 1; // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(13, 101); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(66, 25); this.label2.TabIndex = 2; this.label2.Text = "Major"; // // cbMajor // this.cbMajor.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cbMajor.FormattingEnabled = true; this.cbMajor.Location = new System.Drawing.Point(97, 98); this.cbMajor.Name = "cbMajor"; this.cbMajor.Size = new System.Drawing.Size(230, 33); this.cbMajor.TabIndex = 3; // // rdoFreshman // this.rdoFreshman.AutoSize = true; this.rdoFreshman.Location = new System.Drawing.Point(80, 41); this.rdoFreshman.Name = "rdoFreshman"; this.rdoFreshman.Size = new System.Drawing.Size(139, 29); this.rdoFreshman.TabIndex = 4; this.rdoFreshman.TabStop = true; this.rdoFreshman.Text = "Freshman"; this.rdoFreshman.UseVisualStyleBackColor = true; // // rdoSophmore // this.rdoSophmore.AutoSize = true; this.rdoSophmore.Location = new System.Drawing.Point(80, 76); this.rdoSophmore.Name = "rdoSophmore"; this.rdoSophmore.Size = new System.Drawing.Size(141, 29); this.rdoSophmore.TabIndex = 5; this.rdoSophmore.TabStop = true; this.rdoSophmore.Text = "Sophmore"; this.rdoSophmore.UseVisualStyleBackColor = true; // // rdoJunior // this.rdoJunior.AutoSize = true; this.rdoJunior.Location = new System.Drawing.Point(80, 111); this.rdoJunior.Name = "rdoJunior"; this.rdoJunior.Size = new System.Drawing.Size(102, 29); this.rdoJunior.TabIndex = 6; this.rdoJunior.TabStop = true; this.rdoJunior.Text = "Junior"; this.rdoJunior.UseVisualStyleBackColor = true; // // rdoSenior // this.rdoSenior.AutoSize = true; this.rdoSenior.Location = new System.Drawing.Point(80, 146); this.rdoSenior.Name = "rdoSenior"; this.rdoSenior.Size = new System.Drawing.Size(105, 29); this.rdoSenior.TabIndex = 7; this.rdoSenior.TabStop = true; this.rdoSenior.Text = "Senior"; this.rdoSenior.UseVisualStyleBackColor = true; // // chkFirstTimeStudent // this.chkFirstTimeStudent.AutoSize = true; this.chkFirstTimeStudent.Location = new System.Drawing.Point(19, 402); this.chkFirstTimeStudent.Name = "chkFirstTimeStudent"; this.chkFirstTimeStudent.Size = new System.Drawing.Size(219, 29); this.chkFirstTimeStudent.TabIndex = 8; this.chkFirstTimeStudent.Text = "First Time Student"; this.chkFirstTimeStudent.UseVisualStyleBackColor = true; // // btnRegister // this.btnRegister.Location = new System.Drawing.Point(19, 475); this.btnRegister.Name = "btnRegister"; this.btnRegister.Size = new System.Drawing.Size(308, 58); this.btnRegister.TabIndex = 9; this.btnRegister.Text = "Register Student"; this.btnRegister.UseVisualStyleBackColor = true; this.btnRegister.Click += new System.EventHandler(this.btnRegister_Click); // // lstRegisterStudents // this.lstRegisterStudents.FormattingEnabled = true; this.lstRegisterStudents.ItemHeight = 25; this.lstRegisterStudents.Location = new System.Drawing.Point(369, 35); this.lstRegisterStudents.Name = "lstRegisterStudents"; this.lstRegisterStudents.SelectionMode = System.Windows.Forms.SelectionMode.None; this.lstRegisterStudents.Size = new System.Drawing.Size(473, 504); this.lstRegisterStudents.TabIndex = 10; // // grpBoxLevel // this.grpBoxLevel.Controls.Add(this.rdoFreshman); this.grpBoxLevel.Controls.Add(this.rdoSophmore); this.grpBoxLevel.Controls.Add(this.rdoJunior); this.grpBoxLevel.Controls.Add(this.rdoSenior); this.grpBoxLevel.Location = new System.Drawing.Point(19, 161); this.grpBoxLevel.Name = "grpBoxLevel"; this.grpBoxLevel.Size = new System.Drawing.Size(308, 211); this.grpBoxLevel.TabIndex = 11; this.grpBoxLevel.TabStop = false; this.grpBoxLevel.Text = "Level"; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(891, 572); this.Controls.Add(this.grpBoxLevel); this.Controls.Add(this.lstRegisterStudents); this.Controls.Add(this.btnRegister); this.Controls.Add(this.chkFirstTimeStudent); this.Controls.Add(this.cbMajor); this.Controls.Add(this.label2); this.Controls.Add(this.txtName); this.Controls.Add(this.label1); this.Name = "Form1"; this.Text = "Student Registration"; this.Load += new System.EventHandler(this.Form1_Load); this.grpBoxLevel.ResumeLayout(false); this.grpBoxLevel.PerformLayout(); this.ResumeLayout(false); this.PerformLayout();

}

#endregion

private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox txtName; private System.Windows.Forms.Label label2; private System.Windows.Forms.ComboBox cbMajor; private System.Windows.Forms.RadioButton rdoFreshman; private System.Windows.Forms.RadioButton rdoSophmore; private System.Windows.Forms.RadioButton rdoJunior; private System.Windows.Forms.RadioButton rdoSenior; private System.Windows.Forms.CheckBox chkFirstTimeStudent; private System.Windows.Forms.Button btnRegister; private System.Windows.Forms.ListBox lstRegisterStudents; private System.Windows.Forms.GroupBox grpBoxLevel; } }

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 Assignment2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }

private void Form1_Load(object sender, EventArgs e) { string[] majors = new string[] { "Business Info. Systems", "Chemsitry", "Business Admin.", "Computer Science", "Undeclared" };

foreach (string major in majors) { cbMajor.Items.Remove(major); } }

private void btnRegister_Click(object sender, EventArgs e) { //Get the student name string studentName = "student name";

//Get the student major string studentMajor = cbMajor.Text;

//Get the student level string studentLevel = GetStudentLevel();

//Get the first time student indicator bool isFirstTimeStudent = chkFirstTimeStudent.Checked;

//Add the student information to the list box var studentInformation = studentName + " " + studentMajor + " " + studentLevel;

lstRegisterStudents.Items.Add(studentInformation); }

private string GetStudentLevel() { string level = "";

if (rdoFreshman.Checked == false) level = "Freshman"; if (rdoSophmore.Checked == true) level = "Sophmore"; if (rdoJunior.Checked == true) level = "Junior"; if (rdoSenior.Checked == false) level = "Senior";

if (level == "") { throw new Exception("No student level was chosen"); } else { return level; } } } }

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

More Books

Students also viewed these Databases questions