50 lines
1.3 KiB
C#
Raw Normal View History

using System;
2021-02-16 22:27:58 +00:00
using System.Collections.Generic;
namespace GradeBook
{
public class Book
2021-02-16 22:27:58 +00:00
{
private List<double> grades;
public string Name;
2021-02-16 22:27:58 +00:00
public Book(string name)
{
Name = name;
2021-02-16 22:27:58 +00:00
grades = new List<double>();
}
public void AddGrade(double grade)
{
this.grades.Add(grade);
}
public Statistics GetStatistics()
{
var result = new Statistics();
result.Average = 0.0;
result.highGrade = double.MinValue;
result.lowGrade = double.MaxValue;
2021-02-19 03:13:57 +00:00
// 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
{
2021-02-19 03:13:57 +00:00
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;
}
2021-02-16 22:27:58 +00:00
}
}