Question: Creating an Array to list a Team Roster in C# Assignment Description: In this application your user will enter how many people they want on
Creating an Array to list a Team Roster in C#
Assignment Description: In this application your user will enter how many people they want on their team and then click submit. Once the submit button is clicked the textbox to enter how many people can be on a roster is disabled. The user should see how many seats are open and are remaining. Upon initial submission there should be 0 team members displayed and spots open should match that from the text box. As users are added to a team the spots open should decrease and the number of total members should increase. At the same time the team member roster should append the new team member to the bottom of the roster. Add team should be a method and have entries passed to the array for storage. The clear roster button should clear the array and reset the form to allow a new array entry. Clearing the roster should also be a method that is called.
The code I am using so far has an error at line 100. I am having difficulty with keeping track of the array slots while appending the text from the second text box to the list box.
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 Lab6_TeamRoster_CRupe { public partial class FrmTeamRoster : Form { //Declare global array decimal[] SingleArray; decimal Value = 0.0m; int intSlotsOpen = 0, intMaxSize = 0, i = 0, intSelectedIndex = 0;
// Declare size variable as local so it wont reset each itteration. int intSize;
public FrmTeamRoster() { InitializeComponent(); } //Button Click event to create the array private void BtnSubmit_Click(object sender, EventArgs e) { //Declare Exception Object Exception ex = new Exception();
//get array size from user intSize = Convert.ToInt32(TxtSize.Text);
try {
//Call the Create Array Method CreateArray(intSize);
} catch (FormatException) { MessageBox.Show("Please enter an integer value for Array Size", "Array Size Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (ArgumentNullException) { MessageBox.Show("Please enter an integer value for Array Size", "Null Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } //Button click event to add member to array private void BtnAddMember_Click(object sender, EventArgs e) { try { // get value to add to the array from user String Member = TxtMemberName.Text;
//send value to the add item to array method AddArrayItem(Convert.ToDecimal(Member)); } catch (FormatException) { MessageBox.Show("Not in the correct Data Type should be a decimal Value", "Format Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void BtnClear_Click(object sender, EventArgs e) { LstMembers.Items.Clear(); TxtSize.Enabled = true; this.BtnSubmit.Enabled = true; } public void DisplayArray() { //Display Array Contents for (int j = 0; j < SingleArray.Length; j++) { //Display only those items that are not equal to 0. if (SingleArray[j].ToString() != "0") LstMembers.Items.Add(SingleArray[j].ToString()); } } //Method to Add Array Item public void AddArrayItem(Decimal Value) {
if (intSlotsOpen > 0 && i < intMaxSize) { //remove an open slot intSlotsOpen -= 1;
//add new item at current slot SingleArray = Value;
//increment current slot up by one. i += 1;
//Dispaly current and remaining slots open this.LblCurrentMembers.Text = i.ToString(); //Display Current Size of Array this.LblOpenSpots.Text = intSlotsOpen.ToString();
} } //Method to create array public void CreateArray(int size) { //size the array based on users input SingleArray = new decimal[size]; intMaxSize = size; intSlotsOpen = size;
//Disable new array creation TxtSize.Enabled = false; this.BtnSubmit.Enabled = false; MessageBox.Show("Team Roster has been Created", "Created", MessageBoxButtons.OK, MessageBoxIcon.Information);
} } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
