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 02:30:04 +00:00
|
|
|
public class Book
|
2021-02-16 22:27:58 +00:00
|
|
|
{
|
|
|
|
private List<double> grades;
|
2021-02-22 03:28:38 +00:00
|
|
|
|
|
|
|
private string name;
|
|
|
|
public string Name
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (!String.IsNullOrEmpty(value))
|
|
|
|
{
|
|
|
|
name = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 22:27:58 +00:00
|
|
|
|
|
|
|
public Book(string name)
|
|
|
|
{
|
2021-02-18 01:41:40 +00:00
|
|
|
Name = name;
|
2021-02-16 22:27:58 +00:00
|
|
|
grades = new List<double>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void AddGrade(double grade)
|
|
|
|
{
|
2021-02-22 00:56:24 +00:00
|
|
|
if (grade <= 100 && grade >= 0)
|
|
|
|
{
|
|
|
|
this.grades.Add(grade);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
throw new ArgumentException($"Invalid {nameof(grade)}");
|
|
|
|
}
|
2021-02-16 22:27:58 +00:00
|
|
|
}
|
2021-02-16 22:34:31 +00:00
|
|
|
|
2021-02-22 03:28:38 +00:00
|
|
|
public void AddGrade(char letter)
|
2021-02-19 03:54:21 +00:00
|
|
|
{
|
|
|
|
switch (letter)
|
|
|
|
{
|
|
|
|
case 'A':
|
|
|
|
AddGrade(90);
|
|
|
|
break;
|
|
|
|
case 'B':
|
|
|
|
AddGrade(80);
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
AddGrade(70);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
AddGrade(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-19 03:54:21 +00:00
|
|
|
foreach (var grade in this.grades)
|
2021-02-16 22:34:31 +00:00
|
|
|
{
|
2021-02-19 03:54:21 +00:00
|
|
|
result.lowGrade = Math.Min(grade, result.lowGrade);
|
|
|
|
result.highGrade = Math.Max(grade, result.highGrade);
|
|
|
|
result.Average += grade;
|
|
|
|
}
|
|
|
|
|
2021-02-17 12:33:05 +00:00
|
|
|
result.Average /= grades.Count;
|
2021-02-19 04:33:27 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-02-17 12:33:05 +00:00
|
|
|
return result;
|
2021-02-16 22:34:31 +00:00
|
|
|
}
|
2021-02-16 22:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|