Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I could really use some help with this question! The code must be done with a C# form, and must be super easy to read

I could really use some help with this question!

The code must be done with a C# form, and must be super easy to read as I am a beginner. Please make it as simple as possible.

---------------------------------------------------------------------------------------------------

In this exercise, youll modify the Score Calculator form the code below so the scores are stored in a list instead of an array.

Example of what it shoud look like:

image text in transcribed

image text in transcribed

1.Your exercise name is Assignment6 \Ex2_ScoreCalculator.

2. Replace the declaration for the array variable with a declaration for a List object,

and delete the class variable for the score count.

3. Modify the Click event handler for the Add button so it adds the score thats entered by the user to the list.

In addition, delete the statement that increments the score count variable you deleted.

Then, declare a local variable to store the count, and assign the Count property of the list to this variable.

4. Modify the Click event handler for the Clear Scores button so it removes any scores that have been added to the list.

5. Modify the Click event handler for the Display Scores button so it sorts the scores in the list and then displays them in a dialog box.

6. Test the application to be sure it works correctly.

----------------------------------------------------------------------------------------

The code that needs to be modified!

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 ScoreCalculator { public partial class Form1 : Form { public Form1() { InitializeComponent(); } int total = 0; int count = 0; int average; int[] scoreA = new int[20]; private void Form1_Load(object sender, EventArgs e) { txtAverage.Enabled = false; txtScoreCount.Enabled = false; txtScoreTotal.Enabled = false; }

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

private void btnAdd_Click(object sender, EventArgs e) { try { if (IsValidData()) { int score= Convert.ToInt32(txtScore.Text); scoreA[count] = score; total += score; count += 1; average = total / count; txtScoreTotal.Text = total.ToString(); txtScoreCount.Text = count.ToString(); txtAverage.Text = average.ToString(); txtScore.Focus(); } } catch (Exception e1) { MessageBox.Show("Exception is "+e1); } }

private void btnClear_Click(object sender, EventArgs e) { total = 0; txtScore.Text = ""; txtScoreTotal.Text = ""; txtScoreCount.Text = ""; txtAverage.Text = ""; Array.Clear(scoreA , 0, scoreA .Length); count = 0; txtScore.Focus();

}

private void btnDisplay_Click(object sender, EventArgs e) { string s1=""; Array.Sort(scoreA ); for (int i = 0; i

s1=s1+scoreA[i]+ Environment.NewLine; } MessageBox.Show(s1,"Sorted Scores"); } public bool IsValidData() { return IsPresent(txtScore, "Score:") && IsInt32(txtScore, "Score:") && IsWithinRange(txtScore, "Score:", 0, 100); }

public bool IsPresent(TextBox textBox, string name) { if (textBox.Text == "") { MessageBox.Show(name + " is a required field, please enter a number between 0 and 100.", "Entry Error"); textBox.Focus(); return false; } return true; }

public bool IsInt32(TextBox textBox, string name) { try { Convert.ToInt32(textBox.Text); return true; } catch (FormatException) { MessageBox.Show(name + "must be a number between 0 and 100.", "Entry Error"); textBox.Focus(); return false; } }

public bool IsWithinRange(TextBox textBox, string name, decimal min, decimal max) { decimal number = Convert.ToDecimal(textBox.Text); if (number max) { MessageBox.Show(name + " must be between " + min + " and " + max + ".", "Entry Error"); textBox.Focus(); return false; } return true; } }

}

------------------------------------------------------------------

Thanks!

og Score Calculator D Score: 98 Add Score total 472 Score count 5 Average lay Scores Clear Scores

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

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

Students also viewed these Databases questions

Question

7. It is advisable to do favors for people whenever possible.

Answered: 1 week ago

Question

9. Power and politics can be destructive forces in organizations.

Answered: 1 week ago