Skip to content

Commit

Permalink
Trocando array Item[] por ArrayList<Item>
Browse files Browse the repository at this point in the history
  • Loading branch information
vigusmao committed Apr 7, 2021
1 parent b83cc0d commit 0c7116a
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions Siguinha/src/Aluno.java
@@ -1,3 +1,4 @@
import java.util.ArrayList;
import java.util.Calendar;

public class Aluno {
Expand All @@ -18,8 +19,7 @@ public class Aluno {

private Periodo periodoIngresso;

private ItemHistorico[] historico;
private int contItensHistorico;
private ArrayList<ItemHistorico> historico;

public final static int TAMANHO_MAXIMO_DO_NOME = 30;

Expand All @@ -32,8 +32,7 @@ public Aluno(long dre, String nome) {
this.dre = dre;
this.nome = nome;

this.historico = new ItemHistorico[4];
this.contItensHistorico = 0;
this.historico = new ArrayList<>(); // com <>, o compilador substitui por <ItemHistorico>

Calendar calendar = Calendar.getInstance();
int ano = calendar.get(Calendar.YEAR);
Expand Down Expand Up @@ -116,11 +115,7 @@ public void inserirItemHistorico(

ItemHistorico novoItem = new ItemHistorico(
disciplina, mediaFinal, periodo);
if (this.contItensHistorico == this.historico.length) {
// TRATAR OVERFLOW: copiar tudo para um array maior

}
this.historico[this.contItensHistorico++] = novoItem;
this.historico.add(novoItem);
}

// atualizar creditos
Expand Down Expand Up @@ -148,16 +143,16 @@ public void inserirItemHistorico(
public String getHistoricoParaImpressao() {
String resultado = "Aluno(a): " + this.nome +
" (DRE: " + this.dre + ")\n";
for (int i = 0; i < this.contItensHistorico; i++) {
ItemHistorico itemHistorico = this.historico[i];
for (int i = 0; i < this.historico.size(); i++) {
ItemHistorico itemHistorico = this.historico.get(i);
resultado += itemHistorico.periodo.getAno();
resultado += ".";
resultado += itemHistorico.periodo.getSemestre();
resultado += " - ";
resultado += itemHistorico.disciplinaCursada.getNome();
resultado += " - ";
resultado += String.format("%.1f", itemHistorico.mediaFinal);
if (i != this.contItensHistorico - 1) { // se não é o último item...
if (i != this.historico.size() - 1) { // se não é o último item...
resultado += "\n";
}
}
Expand Down

0 comments on commit 0c7116a

Please sign in to comment.