private static List <int> sortedScores = new List <int>(); //This stores the scores to later sort them. private void btn_Add_Click(object sender, EventArgs e) { if (IsValid()) //If the data is valid th App continues, else it will show a message. { score = Convert.ToInt32(txt_Score.Text); count++; //Keeps adding the number of time a new number is added. scoreTotal += score; //Total score method MethodsClass.ScoreTotal(lbl_ScoreTotal, scoreTotal, score); //Average score method, //sum of scoreTotal is divided by the new count total number. MethodsClass.Average(lbl_Average, scoreTotal, count); unsortedScores.Add(score); //This line adds the new score to the ArrayList and stores it. sortedScores.Add(score); //This adds to the list to sort. lbl_ScoreCount.Text = count.ToString(); //This display the count of scores that have been entered. sortedScores.Sort(); //The list is sorted to keep track of the min and max numbers. //Everytime a new score is entered the lables display their respective data out for Min and Max. lbl_MinScore.Text = sortedScores[0].ToString(); lbl_MaxScore.Text = sortedScores[sortedScores.Count - 1].ToString(); txt_Score.Focus(); //Set focus back to score box. txt_Score.Text = String.Empty; //Sets the score box back to empty.l } }
//Clear all entries. private void btn_ClearScores_Click(object sender, EventArgs e) { //Clears all the entries in the txt and lbl boxes. MethodsClass.ValuesToZero(unsortedScores, sortedScores); score = 0; count = 0; scoreTotal = 0; MethodsClass.Txt_Lbl_Emptied(txt_Score, lbl_Average, lbl_ScoreCount, lbl_ScoreTotal, lbl_MaxScore, lbl_MinScore); txt_Score.Focus(); }