Exercício 4:
public class Student
{
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime DateBirth { get; set; }
public int Age => (int)((DateTime.Today - DateBirth).TotalDays / 365);
public List<double> Notes = new List<double>();
public string DetailedDescription => $"Name: {FirstName} {LastName} - Age: {Age}";
public Student(string firstName, string lastName, DateTime dateBirth, List<double> notes)
{
FirstName = firstName;
LastName = lastName;
DateBirth = dateBirth;
Notes = notes;
}
}
public class Teacher
{
public string FirstName { get; set; }
public string LastName { get; set; }
private List<Discipline> _disciplines = new List<Discipline>();
public string DetailedDescription => $"Teacher: {FirstName} {LastName}";
public Teacher(string firstName, string lastName)
{
FirstName = firstName;
LastName = lastName;
}
public void AddDiscipline(Discipline discipline)
{
_disciplines.Add(discipline);
}
public void ShowDisciplines()
{
Console.WriteLine($"Subjects taught by Professor {FirstName}: ");
foreach (Discipline discipline in _disciplines)
{
Console.WriteLine(discipline.Name);
}
Console.WriteLine("");
}
}
public class Discipline
{
public string Name { get; set; }
private List<Student> _students = new List<Student>();
public Discipline(string name)
{
Name = name;
}
public void AddStudent(Student student)
{
_students.Add(student);
}
public void ShowStudents()
{
Console.WriteLine($"Students enrolled in the {Name} course:");
foreach (Student student in _students)
{
Console.WriteLine(student.DetailedDescription);
}
}
}
Student carlos = new Student("Carlos", "Eduardo", new DateTime(2003, 7, 15), new List<double> { 10, 9.8, 5.0, 7.0});
Student ana = new Student("Ana", "Clara", new DateTime(2004, 12, 1), new List<double> { 5, 4, 10, 10});
Student roberto = new Student("Roberto", "Silva", new DateTime(2002, 4, 4), new List<double> { 10, 10, 9.9, 2.0});
Teacher gustavo = new Teacher("Gustavo", "Fernando");
Discipline discipline = new Discipline("Mathematics");
gustavo.AddDiscipline(discipline);
gustavo.ShowDisciplines();
discipline.AddStudent(carlos);
discipline.AddStudent(ana);
discipline.AddStudent(roberto);
discipline.ShowStudents();