-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAluno.java
More file actions
52 lines (43 loc) · 1.43 KB
/
Copy pathAluno.java
File metadata and controls
52 lines (43 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.util.ArrayList;
public class Aluno {
// Atributos do aluno
int id;
String nome;
String nascimento;
String CPF;
int idCurso;
Curso curso; // Referência ao curso do aluno
// Lista estática que armazena todos os alunos criados
static ArrayList<Aluno> alunos = new ArrayList<>();
// Construtor que inicializa o aluno com um ID de curso
public Aluno(int id, String nome, String nascimento, String CPF, int idCurso) {
this.id = id;
this.nome = nome;
this.nascimento = nascimento;
this.CPF = CPF;
this.idCurso = idCurso;
// Adiciona o aluno à lista de alunos
alunos.add(this);
}
// Construtor alternativo que recebe diretamente um objeto Curso
public Aluno(int id, String nome, String nascimento, String CPF, Curso curso) {
this.id = id;
this.nome = nome;
this.nascimento = nascimento;
this.CPF = CPF;
this.curso = curso;
// Adiciona o aluno à lista de alunos
alunos.add(this);
}
// Método estático que conta quantos alunos estão em um determinado curso
static int contarAlunosPorCurso(int idCurso) {
int cont = 0;
for (Aluno aluno : alunos) {
// Verifica se o ID do curso do aluno corresponde ao ID fornecido
if (aluno.idCurso == idCurso) {
cont++;
}
}
return cont;
}
}