Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Dynamic;
- using System.Linq;
- using System.Reflection.Metadata.Ecma335;
- using System.Security.Cryptography.X509Certificates;
- using System.Text;
- namespace ClassroomProject
- {
- public class Classroom
- {
- public Classroom(int capacity)
- {
- this.Capacity = capacity;
- this.AllStudents = new List<Student>(capacity);
- }
- public int Capacity { get; set; }
- public List<Student> AllStudents { get; set; }
- public int Count => AllStudents.Count;
- //Method RegisterStudent(Student student) – adds an entity to the students if there is an empty seat for the student.
- //Returns "Added student {firstName} {lastName}" if the student is successfully added
- //Returns "No seats in the classroom" – if there are no more seats in the classroom
- public string RegisterStudent(Student student)
- {
- if (this.Capacity > this.Count)
- {
- AllStudents.Add(student);
- return $"Added student {student.FirstName} {student.LastName}";
- }
- return "No seats in the classroom";
- }
- // Method DismissStudent(string firstName, string lastName) – removes the student by the given names
- // Returns "Dismissed student {firstName} {lastName}" if the student is successfully dismissed
- // Returns "Student not found" if the student is not in the classroom
- public string DismissStudent(string firstName, string lastName)
- {
- if (AllStudents.Any(x => x.FirstName == firstName && x.LastName == lastName))
- {
- var removedStudent = AllStudents.FirstOrDefault(x => x.FirstName == firstName && x.LastName == lastName);
- AllStudents.Remove(removedStudent);
- return $"Dismissed student {removedStudent?.FirstName} {removedStudent?.LastName}";
- }
- return "Student not found";
- }
- //• Method GetSubjectInfo(string subject) – returns all the students with the given subject in the following format:
- //"Subject: {subjectName}
- //Students:
- //{firstName {lastName}
- //{ firstName} { lastName}"
- public string GetSubjectInfo(string subject)
- {
- if (AllStudents.Any(s => s.Subject == subject))
- {
- StringBuilder result = new StringBuilder();
- result.AppendLine($"Subject: {subject}");
- result.AppendLine("Students:");
- foreach (var student in AllStudents.Where(student => student.Subject == subject))
- {
- result.AppendLine($"{student.FirstName} {student.LastName}");
- }
- return result.ToString().TrimEnd();
- }
- return "No students enrolled for the subject";
- }
- //• Method GetStudentsCount() – returns the count of the students in the classroom.
- public string GetStudentsCount()
- {
- return $"{AllStudents.Count}";
- }
- //• Method GetStudent(string firstName, string lastName) – returns the student with the given names.
- public Student GetStudent(string firstName, string lastName)
- {
- var student = AllStudents.FirstOrDefault(x => x.FirstName == firstName && x.LastName == lastName);
- return student;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement