2021-02-16 22:34:31 +00:00
|
|
|
using System;
|
2021-02-16 22:27:58 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace GradeBook
|
|
|
|
{
|
2021-02-17 12:33:05 +00:00
|
|
|
// public class Statistics
|
|
|
|
// {
|
|
|
|
// public double Average;
|
|
|
|
// public double highGrade;
|
|
|
|
// public double lowGrade;
|
|
|
|
// }
|
2021-02-17 02:30:04 +00:00
|
|
|
public class Book
|
2021-02-16 22:27:58 +00:00
|
|
|
{
|
|
|
|
private List<double> grades;
|
|
|
|
private string name;
|
|
|
|
|
|
|
|
public Book(string name)
|
|
|
|
{
|
|
|
|
this.name = name;
|
|
|
|
grades = new List<double>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void AddGrade(double grade)
|
|
|
|
{
|
|
|
|
this.grades.Add(grade);
|
|
|
|
}
|
2021-02-16 22:34:31 +00:00
|
|
|
|
2021-02-17 12:33:05 +00:00
|
|
|
public Statistics GetStatistics()
|
2021-02-16 22:34:31 +00:00
|
|
|
{
|
2021-02-17 12:33:05 +00:00
|
|
|
var result = new Statistics();
|
|
|
|
result.Average = 0.0;
|
|
|
|
result.highGrade = double.MinValue;
|
|
|
|
result.lowGrade = double.MaxValue;
|
2021-02-16 22:34:31 +00:00
|
|
|
|
2021-02-17 12:33:05 +00:00
|
|
|
foreach (var grade in this.grades)
|
2021-02-16 22:34:31 +00:00
|
|
|
{
|
2021-02-17 12:33:05 +00:00
|
|
|
result.lowGrade = Math.Min(grade, result.lowGrade);
|
|
|
|
result.highGrade = Math.Max(grade, result.highGrade);
|
|
|
|
result.Average += grade;
|
2021-02-16 22:34:31 +00:00
|
|
|
}
|
|
|
|
|
2021-02-17 12:33:05 +00:00
|
|
|
result.Average /= grades.Count;
|
|
|
|
return result;
|
2021-02-16 22:34:31 +00:00
|
|
|
}
|
2021-02-16 22:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|