Skip to content

Instantly share code, notes, and snippets.

@devrsantos
Last active May 18, 2022 01:57
Show Gist options
  • Save devrsantos/ac623249a46c8373ee9a59b511ccf191 to your computer and use it in GitHub Desktop.
Save devrsantos/ac623249a46c8373ee9a59b511ccf191 to your computer and use it in GitHub Desktop.
class Matricula {
constructor(nome, quantidadeFaltas, notas) {
this.nome = nome;
this.quantidadeFaltas = quantidadeFaltas;
this.notas = notas;
}
calcularMedia() {
let media = this.notas.reduce((nota, i) => {
return nota + i;
});
return media / this.notas.length;
}
faltas() {
return (this.quantidadeFaltas += 1);
}
}
let curso = {
nomeCurso: 'Administração',
notaAprovacao: 7,
faltaMaxima: 3,
listaEstudantes: [],
listaResultado: [],
adicionaAluno(nome, falta, notas) {
let aluno = new Matricula(nome, falta, notas);
this.listaEstudantes.push(aluno);
},
verificarSituacaoAluno(nome) {
this.listaEstudantes.forEach((aluno) => {
if (aluno.nome == nome) {
let mediaParcial = aluno.notas.reduce((n, i) => {
return n + i;
});
let mediaFinal = mediaParcial / aluno.notas.length;
if (aluno.quantidadeFaltas == this.faltaMaxima) {
let notaFinalComAcrescimo =
this.notaAprovacao + (this.notaAprovacao / 100) * 10;
if (mediaFinal >= notaFinalComAcrescimo) {
console.log(`TRUE`);
} else {
console.log(`FALSE`);
}
} else {
if (mediaFinal >= this.notaAprovacao) {
console.log(`TRUE`);
} else {
console.log(`FALSE`);
}
}
}
});
},
gerarLista() {
this.listaEstudantes.forEach((aluno) => {
let mediaParcial = aluno.notas.reduce((n, i) => {
return n + i;
});
let mediaFinal = mediaParcial / aluno.notas.length;
if (aluno.quantidadeFaltas == this.faltaMaxima) {
let notaFinalComAcrescimo =
this.notaAprovacao + (this.notaAprovacao / 100) * 10;
if (mediaFinal >= notaFinalComAcrescimo) {
this.listaResultado.push(`TRUE`);
} else {
this.listaResultado.push(`FALSE`);
}
} else {
if (mediaFinal >= this.notaAprovacao) {
this.listaResultado.push(`TRUE`);
} else {
this.listaResultado.push(`FALSE`);
}
}
});
},
};
curso.adicionaAluno('Renan', 2, [8, 8, 7, 7]);
curso.adicionaAluno('Allyssa', 2, [7, 7, 8, 8]);
curso.adicionaAluno('Aidan', 1, [7, 6, 5, 4]);
curso.verificarSituacaoAluno('Renan');
curso.verificarSituacaoAluno('Allyssa');
curso.verificarSituacaoAluno('Aidan');
curso.gerarLista();
console.log(curso.listaResultado);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment