Encapsulate all methods within Book class
parent
eedc0c5329
commit
b88985d236
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace GradeBook
|
||||
|
@ -17,6 +18,26 @@ namespace GradeBook
|
|||
{
|
||||
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}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -11,25 +11,8 @@ namespace GradeBook
|
|||
var book = new Book("Scott's Grade Book");
|
||||
book.AddGrade(89.1);
|
||||
book.AddGrade(90.5);
|
||||
|
||||
List<double> grades = new List<double>() {12.7, 10.3, 6.11, 4.1};
|
||||
grades.Add(56.1);
|
||||
double result = 0;
|
||||
var highGrade = double.MinValue;
|
||||
var lowGrade = double.MaxValue;
|
||||
|
||||
foreach (var number in 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}");
|
||||
book.AddGrade(87.2);
|
||||
book.ShowStaticstics();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue