Finished Pattern Matching with switch

This commit is contained in:
Jason Zhu 2021-02-19 04:33:27 +00:00
parent dd47f5cf72
commit 41ca2586dc
3 changed files with 22 additions and 9 deletions

View File

@ -52,16 +52,27 @@ namespace GradeBook
result.Average += grade;
}
// var index = 0;
// do
// {
// result.lowGrade = Math.Min(grades[index], result.lowGrade);
// result.highGrade = Math.Max(grades[index], result.highGrade);
// result.Average += grades[index];
// index += 1;
// } while (index < grades.Count);
result.Average /= grades.Count;
switch (result.Average)
{
case var d when d >= 90.0:
result.Letter = 'A';
break;
case var d when d >= 80.0:
result.Letter = 'B';
break;
case var d when d >= 70.0:
result.Letter = 'C';
break;
case var d when d >= 60.0:
result.Letter = 'D';
break;
default:
result.Letter = 'F';
break;
}
return result;
}
}

View File

@ -5,5 +5,6 @@ namespace GradeBook
public double Average;
public double highGrade;
public double lowGrade;
public char Letter;
}
}

View File

@ -21,6 +21,7 @@ namespace GradeBook.Tests
Assert.Equal(85.6, result.Average, 1);
Assert.Equal(90.5, result.highGrade);
Assert.Equal(77.3, result.lowGrade);
Assert.Equal('B', result.Letter);
}
}
}