0
I have the following classes:
public class Aluno
{
public String Nome { get; set; }
public String Ra { get; set; }
public Decimal NotaB1 { get; set; }
public Decimal NotaB2 { get; set; }
public Decimal getMedia()
{
return (NotaB1 + NotaB2) / 2;
}
}
public class AlunoTecnologo : Aluno
{
public Decimal NotaPim { get; set; }
public Decimal getMedia()
{
return NotaPim * 0.2m + base.getMedia();
}
}
I’m simulating the persistence of the data in a comic book, so I created the next class where I create a list to save the students in memory:
public class AlunoDao
{
private List<Aluno> alunos;
public AlunoDao()
{
alunos = new List<Aluno>();
}
public void Adicionar(Aluno aluno)
{
alunos.Add(aluno);
}
public List<Aluno> Listar()
{
return new List<Aluno>(alunos);
}
}
But when saving a AlunoTecnologo
in that list, the average is calculated using the class method Pupil and not of class AlunoTecnologo
where an extra note is inserted. Here is an example of how the code looks:
static void Main(string[] args)
{
Aluno vizu = new Aluno()
{
Nome = "Joao Vizu",
Ra = "N300361",
NotaB1 = 7.5M,
NotaB2 = 10M
};
AlunoTecnologo lais = new AlunoTecnologo()
{
Nome = "Lais Silva",
Ra = "545454",
NotaB1 = 7.5M,
NotaB2 = 10M,
NotaPim = 9M
};
AlunoDao dao = new AlunoDao();
dao.Adicionar(vizu);
dao.Adicionar(lais);
foreach (Aluno aluno in dao.Listar())
{
Console.WriteLine($"Nome: {aluno.Nome}\tNotaB1: {aluno.NotaB1}\tNotaB2: {aluno.NotaB2}\tMedia: {aluno.getMedia()}");
}
Console.ReadKey();
}
What should I do so that I can add to this list the correct data of each student, following the inheritance? I would have to create a DAO class for the AlunoTecnologo
?