I could really use some help with this question! Must be a C# Form application,
ID: 3840755 • Letter: I
Question
I could really use some help with this question!
Must be a C# Form application, and must be basic, and easy to understand as I am new to programming.
------------------------------------------------------------------------------------------------------------------------------------------------
In this exercise, you’ll enhance the Score Calculator form of A5 so it saves the scores the user enters in an array and then lets the user display the sorted scores in a dialog box.
1.Use the ScoreCalculatorStart project as your baseline. This is the Score Calculator from A2-E3.
2.Your exercise name is Assignment6 Ex1_ScoreCalculator (not Assignment6/ ScoreCalculatorStart)
3.You must add exception and validation (see “implement me” comments in the code)
4. Declare a class variable for an array that can hold up to 20 scores.
5. Modify the Click event handler for the Add button so it adds the score that’s entered by the user to the next element in the array. To do that, you can use the score count variable to refer to the element.
6. Move the Clear Scores button as shown above.
Then, modify the Click event handler for this button so it removes any scores that have been added to the array.
(The easiest way to do that is to create a new array and assign it to the array variable)
7. Add a Display Scores button that sorts the scores in the array, displays the scores in a dialog box,
and moves the focus to the Score text box.
Be sure that only the elements that contain scores are displayed.
Test the application to be sure it works correctly
------------------------------------------------------------------------------------------------------------------------------------------
The code that must be modified
namespace ScoreCalculator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int total = 0;
int count = 0;
//something will be here
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);
total += score;
count += 1;
int average = total / count;
txtScoreTotal.Text = total.ToString();
txtScoreCount.Text = count.ToString();
txtAverage.Text = average.ToString();
txtScore.Focus();
}
}
catch (Exception ex)
{
//implement me
//stack, type, message
}
}
//implement me
//private void btnDisplay_Click(object sender, EventArgs e)
//{
//}
private void btnClear_Click(object sender, EventArgs e)
{
total = 0;
txtScore.Text = "";
txtScoreTotal.Text = "";
txtScoreCount.Text = "";
txtAverage.Text = "";
txtScore.Focus();
}
public bool IsValidData()
{
return
// Validate the Score text box
IsPresent(txtScore, "Score") &&
IsInt32(txtScore, "Score") &&
IsWithinRange(txtScore, "Score", 01, 100);
}
public bool IsPresent(TextBox textBox, string name)
{
//implement me
//test and error message
return true;
}
public bool IsInt32(TextBox textBox, string name)
{
//implement me
//test and error message
return true;
}
public bool IsWithinRange(TextBox textBox, string name,
decimal min, decimal max)
{
//implement me
//test and error message
return true;
}
}
}
------------------------------------------------------------------------------------------------
Thanks!
og Score Calculator D Score: 98 Add Score total 472 Score count 5 Average lay Scores Clear ScoresExplanation / Answer
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 < scoreA.Length; 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 < min || number > max)
{
MessageBox.Show(name + " must be between " + min + " and " + max + ".", "Entry Error");
textBox.Focus();
return false;
}
return true;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.