43 lines
1.0 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;
private string name;
public Book(string name)
{
this.name = name;
grades = new List<double>();
}
public void AddGrade(double grade)
{
this.grades.Add(grade);
}
public void ShowStaticstics()
{
double result = 0;
var highGrade = double.MinValue;
var lowGrade = double.MaxValue;
foreach (var number in this.grades)
{
highGrade = Math.Max(number, highGrade);
lowGrade = Math.Min(number, lowGrade);
result += number;
}
result /= grades.Count;
Console.WriteLine($"The average grade is {result:N1}");
Console.WriteLine($"The highest grade is {highGrade:N1}");
Console.WriteLine($"The lowest grade is {lowGrade:N1}");
}
2021-02-16 22:27:58 +00:00
}
}