From a26546e8a441ee622a33d5b0cc8f63d25f0f5f15 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Fri, 1 Mar 2024 13:05:10 +0100 Subject: [PATCH] Solve task 1 --- Tasks/DT1/{DT1_0.cs => DT1.cs} | 29 ++++++++++++++++++++++------- Tasks/DT1/DT1.csproj | 2 +- 2 files changed, 23 insertions(+), 8 deletions(-) rename Tasks/DT1/{DT1_0.cs => DT1.cs} (81%) diff --git a/Tasks/DT1/DT1_0.cs b/Tasks/DT1/DT1.cs similarity index 81% rename from Tasks/DT1/DT1_0.cs rename to Tasks/DT1/DT1.cs index 6bff177..309aa1d 100644 --- a/Tasks/DT1/DT1_0.cs +++ b/Tasks/DT1/DT1.cs @@ -17,9 +17,20 @@ namespace DT1 { } public class StudentClass { - public Func studentSelector = /* TO BE DONE */ - public GradeCalc gradeCalculator = /* TO BE DONE */ - public Func passedSelector = /* TO BE DONE */ + public Func studentSelector = (student, surname) => + { + return string.Compare(student.LastName, surname, true) == 0; + }; + + public GradeCalc gradeCalculator = (grades) => + { + return Math.Round(((grades.Average() / 100 * 5) + 1) * 2, MidpointRounding.AwayFromZero) / 2; + }; + + public Func passedSelector = (student) => + { + return student.Year == GradeLevel.FourthYear && student.Grade >= 4; + }; #region data public List students = new List { @@ -70,15 +81,16 @@ namespace DT1 { } public List SearchStudent(Func select, String lastName) { - List result = new List(); + List result = new() { }; foreach (Student s in students) { if (select(s, lastName)) result.Add(s); } return result; } - public IEnumerable QueryPassed(Func passed) { - return /* TO BE DONE */ + public IEnumerable QueryPassed(Func passed) + { + return students.Where(passed); } static void show(String titel, List students) { @@ -101,7 +113,10 @@ namespace DT1 { } public static class ListUtils { - public static IEnumerable ... /* TO BE DONE */ + public static IEnumerable What(this IList list, Func selector) + { + return list.Where(selector); + } } } diff --git a/Tasks/DT1/DT1.csproj b/Tasks/DT1/DT1.csproj index 2150e37..0af2984 100644 --- a/Tasks/DT1/DT1.csproj +++ b/Tasks/DT1/DT1.csproj @@ -4,7 +4,7 @@ Exe net8.0 enable - enable + disable