3) For task ‘c’, move the code that calculates the grade value based on the diff
ID: 3632271 • Letter: 3
Question
3) For task ‘c’, move the code that calculates the grade value based on the different grading rules from the event handler to its own method.RESTRICTIONS:
i) This method will have, at the least, four parameters; the course name, and the values of the previously initialized assignment grade, midterm grade, and the final grade (a reference to the grades is not required since this method does not modify the value of the grades).
ii) This method will return the calculated grade value in a numerical type of your choice (int, double, decimal).
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;
}
}
}
Explanation / Answer
I haven't run it, so I'm not sure whether it is w/o errors. Tell me if it isn't.
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;
grade = calculateGrade(tbCourse.Text, aGrade, mGrade, fGrade);
}
private int calculateGrade(string courseName, int aGrade, int mGrade, int fGrade)
{
int grade;
switch (courseName)
{
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;
}
return grade;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.