static void Main(string[] args) { //instantiate class Gradebook => invokes constructor (defaults but can be customized) Gradebook book = new Gradebook(); book.AddGrade(91); book.AddGrade(89); book.AddGrade(72); //separates blueprint class from computational class GradeStatistics stats = book.ComputeStatistics(); Console.WriteLine(stats.AverageGrade); Console.WriteLine(stats.HighestGrade); Console.WriteLine(stats.LowestGrade); }
//Gradestatistics is what will be returned - void is used if not returning a value public GradeStatistics ComputeStatistics() { GradeStatistics stats = new GradeStatistics(); float sum = 0; foreach (float grade in grades) { stats.HighestGrade = Math.Max(grade, stats.HighestGrade); stats.LowestGrade = Math.Min(grade, stats.LowestGrade); //adds value of grade into variable sum += grade; } stats.AverageGrade = sum / grades.Count; return(stats); }