-
Notifications
You must be signed in to change notification settings - Fork 30
/
StudentManager.cs
38 lines (36 loc) · 1.22 KB
/
StudentManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
namespace StudentGradeManager;
using System;
using System.Collections.Generic;
public class StudentManager
{
private readonly List<IStudent> _students = [];
public List<IStudent> GetStudentsByID(int studentID)
{
return _students.Where(s => s.ID == studentID).ToList();
}
public List<IStudent> GetStudentsByName(string studentName)
{
return _students.Where(s => s.Name == studentName).ToList();
}
public List<IStudent> GetTopStudents(int count)
{
return _students.OrderByDescending(s => s.GetGPA()).Take(count).ToList();
}
public void AddStudent(IStudent student)
{
if (_students.FirstOrDefault(s => s.ID == student.ID) is null)
_students.Add(student);
else
throw new Exception("Student already exists");
}
public void RemoveStudent(int studentID)
{
var student = _students.FirstOrDefault(s => s.ID == studentID) ?? throw new Exception("Student not found");
_students.Remove(student);
}
public void PrintStudent(int studentID)
{
var student = _students.FirstOrDefault(s => s.ID == studentID) ?? throw new Exception("Student not found");
Console.WriteLine(student.ToString());
}
}