public DiaryStatistics ComputeStatistics() { DiaryStatistics stats = new DiaryStatistics(); float sum = 0f; foreach (var rating in ratings) { sum += rating; } stats.AverageGrade = sum / ratings.Count(); stats.MaxGrade = ratings.Max(); stats.MinGrade = ratings.Min(); return(stats); }
public DiaryStatistics ComputeStats() { // chcemy, żeby metoda zwracałą obiekt DiaryStatistics DiaryStatistics stats = new DiaryStatistics(); var sum = 0f; foreach (var rating in Ratings) { sum += rating; } stats.AverageGrade = sum / Ratings.Count(); stats.MaxGrade = Ratings.Max(); stats.MinGrade = Ratings.Min(); return(stats); }
///<summary> ///Wyliczenie statystyk dzienniczka ///</summary>> public DiaryStatistics ComputeStatistics() { DiaryStatistics stats = new DiaryStatistics(); float sum = 0f; //zmienne pomocnicza foreach (var rating in ratings) //pętla sumująca elementy listy { sum += rating; } stats.AverageGrade = sum / ratings.Count(); //wyliczenie średniej stats.MaxGrade = ratings.Max(); //najwyższa ocena stats.MinGrade = ratings.Min(); //najniższa ocena return(stats); }