Finished Switching with the swtich Statement
parent
009cdc3919
commit
dd47f5cf72
|
@ -19,6 +19,25 @@ namespace GradeBook
|
|||
this.grades.Add(grade);
|
||||
}
|
||||
|
||||
public void AddLetterGrade(char letter)
|
||||
{
|
||||
switch (letter)
|
||||
{
|
||||
case 'A':
|
||||
AddGrade(90);
|
||||
break;
|
||||
case 'B':
|
||||
AddGrade(80);
|
||||
break;
|
||||
case 'C':
|
||||
AddGrade(70);
|
||||
break;
|
||||
default:
|
||||
AddGrade(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Statistics GetStatistics()
|
||||
{
|
||||
var result = new Statistics();
|
||||
|
@ -26,21 +45,21 @@ namespace GradeBook
|
|||
result.highGrade = double.MinValue;
|
||||
result.lowGrade = double.MaxValue;
|
||||
|
||||
// foreach (var grade in this.grades)
|
||||
// {
|
||||
// result.lowGrade = Math.Min(grade, result.lowGrade);
|
||||
// result.highGrade = Math.Max(grade, result.highGrade);
|
||||
// result.Average += grade;
|
||||
// }
|
||||
|
||||
var index = 0;
|
||||
do
|
||||
foreach (var grade in this.grades)
|
||||
{
|
||||
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.lowGrade = Math.Min(grade, result.lowGrade);
|
||||
result.highGrade = Math.Max(grade, result.highGrade);
|
||||
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;
|
||||
return result;
|
||||
|
|
Loading…
Reference in New Issue