Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ClassroomProject
- {
- public class Classroom
- {
- public List<Student> Students { get; set; }
- public int Capacity { get; set; }
- public int Count => Students.Count;
- public Classroom(int capacity)
- {
- Capacity = capacity;
- Students = new List<Student>(capacity);
- }
- public string RegisterStudent(Student student)
- {
- if (this.Count < this.Capacity)
- {
- Students.Add(student);
- return $"Added student {student.FirstName} {student.LastName}";
- }
- else
- {
- return "No seats in the classroom";
- }
- }
- public string DismissStudent(string firstName, string lastName)
- {
- if (Students.Any(f => f.FirstName == firstName && f.LastName == lastName))
- {
- Student toRemove = Students.FirstOrDefault(f => f.FirstName == firstName && f.LastName == lastName);
- Students.Remove(toRemove);
- return $"Dismissed student {toRemove.FirstName} {toRemove.LastName}";
- }
- else
- {
- return "Student not found";
- }
- }
- public string GetSubjectInfo(string subject)
- {
- int counter = 0;
- foreach (Student student in Students)
- {
- if (student.Subject == subject)
- {
- counter++;
- break;
- }
- }
- if (counter > 0)
- {
- StringBuilder result = new StringBuilder();
- result.AppendLine($"Subject: {subject}");
- result.AppendLine("Students:");
- foreach (var student in Students.Where(student => student.Subject == subject))
- {
- result.AppendLine($"{student.FirstName} {student.LastName}");
- }
- return result.ToString().TrimEnd();
- }
- else
- {
- return "No students enrolled for the subject";
- }
- }
- public string GetStudentsCount()
- {
- return $"{Students.Count}";
- }
- public Student GetStudent(string firstName, string lastName)
- {
- Student student = Students.FirstOrDefault(
- x => x.FirstName == firstName
- && x.LastName == lastName);
- return student;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement