4) For task ‘d’, move the code that converts the grade value to a letter grade f
ID: 3632450 • Letter: 4
Question
4) For task ‘d’, move the code that converts the grade value to a letter grade from the event handle to its own method.
RESTRICTIONS:
i) This method will have, at least, one parameter; the calculated grade value
ii) This method will return a string value containing the letter grade
Need to change the code below and make a new method and call.
public partial class Form1 : Form
{
const int BONUS_POINTS = 10;
const int PASS_FAIL_LEVEL = 70;
const double ASSIGNMENT_WEIGHT = 0.50;
const double TEST_WEIGHT = 0.50;
const string PASS_FAIL_COURSE = "INFO1200";
const string EASY_COURSE = "INFO0123";
private void btnCalc_Click(object sender, EventArgs e)
{
bool goodInput = true;
double grade = 0;
string letterGrade;
int aGrade = 0, mGrade = 0, fGrade = 0;
bool loveChecked;
//Calculte the grade according to the course's grading scheme.
switch (tbCourse.Text)
{
case PASS_FAIL_COURSE:
if ((aGrade > PASS_FAIL_LEVEL)
&& ((mGrade > PASS_FAIL_LEVEL) || (fGrade > PASS_FAIL_LEVEL)))
{
grade = 100;
}
else
{
grade = 0;
}
break;
case EASY_COURSE:
if (aGrade > grade)
{
grade = aGrade;
}
if (mGrade > grade)
{
grade = mGrade;
}
if (fGrade > grade)
{
grade = fGrade;
}
break;
default:
grade = aGrade * ASSIGNMENT_WEIGHT;
grade += (mGrade + fGrade) / 2 * TEST_WEIGHT;
break;
}
/*
* Convert grade to a letter grade
*/
if (grade >= 90)
{
letterGrade = "A";
}
else
if (grade >= 80)
{
letterGrade = "B";
}
else
if (grade >= 70)
{
letterGrade = "C";
}
else
if (grade >= 60)
{
letterGrade = "D";
}
else
{
letterGrade = "E";
}
}
}
Explanation / Answer
Here's the method to return the letter grade:
You'll calculate the numerical grade as you currently do and then pass it into the above method to retrieve the corresponding letter grade:
...
...
Hope this helps - let me know if you have any questions.
Joe
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.