Skip to content

Commit

Permalink
Heranca
Browse files Browse the repository at this point in the history
  • Loading branch information
vigusmao committed Apr 14, 2021
1 parent 0ab0b50 commit 95a11fc
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 37 deletions.
20 changes: 20 additions & 0 deletions Siguinha/Siguinha.iml
Expand Up @@ -7,5 +7,25 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="TEST">
<library name="JUnit4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
58 changes: 41 additions & 17 deletions Siguinha/src/Aluno.java
@@ -1,5 +1,4 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Objects;

public class Aluno {
Expand All @@ -12,7 +11,11 @@ public class Aluno {

private final long dre;

// public float cra; // público para leitura e escrita de qualquer lugar do código
// float cra; // "public" APENAS DENTRO DO MESMO package!!!
// protected float cra; // "public" dentro do mesmo package + subclasses
private float cra;

private float numeradorCra;
private float denominadorCra;

Expand All @@ -22,24 +25,29 @@ public class Aluno {

private ArrayList<ItemHistorico> historico;

private int anoNascimento;

public final static int TAMANHO_MAXIMO_DO_NOME = 30;

// --------------------------------
// métodos
// --------------------------------

public Aluno() {
this(0, "Sem Nome"); // chamando a sobrecarga de construtor deste objeto
}

public Aluno(long dre, String nome) {

// super(); // esta linha é acrescentada automaticamente pelo compilador,
// // se nós não chamarmos explicitamente o construtor da superclasse

this.dre = dre;
this.nome = nome;

this.historico = new ArrayList<>(); // com <>, o compilador substitui por <ItemHistorico>

Calendar calendar = Calendar.getInstance();
int ano = calendar.get(Calendar.YEAR);
int mes = calendar.get(Calendar.MONTH);
this.periodoIngresso = new Periodo(
ano, mes <= 6 ? 1 : 2);
this.periodoIngresso = Siguinha.obterPeriodoCorrente();

this.cra = 0; // desnecessário, pois 0 é o valor default de float
this.numeradorCra = 0;
Expand Down Expand Up @@ -77,6 +85,14 @@ public long getDre() {
return dre;
}

public int getAnoNascimento() {
return anoNascimento;
}

public int getIdade() {
return Siguinha.obterAnoCorrente() - anoNascimento;
}

// ATENÇÃO: NÃO QUEREMOS UM SETTER PÚBLICO PARA O CRA!!!!!!
//
// public void setCra(float cra) {
Expand All @@ -87,6 +103,11 @@ public long getDre() {
// }
//

public void inserirItemHistorico(Disciplina disciplina, float mediaFinal) {
Periodo periodoCorrente = Siguinha.obterPeriodoCorrente();
inserirItemHistorico(disciplina, mediaFinal, periodoCorrente);
}

public void inserirItemHistorico(
Disciplina disciplina, float mediaFinal, Periodo periodo) {

Expand Down Expand Up @@ -127,17 +148,6 @@ public void inserirItemHistorico(
this.creditosAcumulados += disciplina.getCreditos();
}

// atualizar CRA:

// float numerador = 0;
// float denominador = 0;
// for (ItemHistorico itemHistorico : this.historico) {
// int creditos = itemHistorico.disciplinaCursada.getCreditos();
// numerador += itemHistorico.mediaFinal * creditos;
// denominador += creditos;
// }
// this.cra = numerador / denominador;

// outro jeito de atualizar o CRA (melhor performance)
this.numeradorCra += mediaFinal * disciplina.getCreditos();
this.denominadorCra += disciplina.getCreditos();
Expand Down Expand Up @@ -180,6 +190,20 @@ public boolean equals(Object o) {
Objects.equals(nome, aluno.getNome());
}

// @Override
// public String toString() { // override (assinatura idêntica)
// return String.format("%s (DRE: %d)", nome, dre);
// }
//
// public String toString(int maxLength) { // overload (sobrecarga)
// String toStringSemLimite = toString();
// return toStringSemLimite.substring(0, maxLength);
// }
//
// public String toString(char separador) { // overload
// return String.format("%s%c%d", nome, separador, dre);
// }

// inner class (classe auxiliar, visível apenas de dentro da classe Aluno)
private class ItemHistorico {

Expand Down
3 changes: 3 additions & 0 deletions Siguinha/src/Disciplina.java
@@ -1,3 +1,5 @@
import sun.misc.Queue;

public class Disciplina {

private String nome;
Expand Down Expand Up @@ -29,6 +31,7 @@ public void setCreditos(int creditos) {
}

public String getCodigo() {
Queue q = new Queue();
return codigo;
}
}
39 changes: 39 additions & 0 deletions Siguinha/src/MonitorDeDisciplina.java
@@ -0,0 +1,39 @@
public class MonitorDeDisciplina extends Aluno {

public static final float CRA_MINIMO_PARA_RENOVACAO_MONITORIA = 6.0f;

private Disciplina disciplina;

public MonitorDeDisciplina() {
super();
}

public MonitorDeDisciplina(long dre, String nome, Disciplina disciplina) {
super(dre, nome);
this.disciplina = disciplina;
}

public void verificarNotas() {
// ToDo ...
}

public void renovarMonitoria() {
if (this.getCra() >= CRA_MINIMO_PARA_RENOVACAO_MONITORIA) {
// ToDo ...
}
}

@Override
public String toString() {
return "MonitorDeDisciplina{" +
"disciplina=" + disciplina +
'}';
}

@Override
public String getHistoricoParaImpressao() {
String resultado = "HISTÓRICO DE MONITOR!!!!!!!!\n" +
super.getHistoricoParaImpressao();
return resultado;
}
}
54 changes: 34 additions & 20 deletions Siguinha/src/Siguinha.java
@@ -1,38 +1,52 @@
import java.util.Calendar;

public class Siguinha {

public final static float MEDIA_MINIMA_PARA_APROVACAO = 5.0f;

private static Periodo periodoCorrente = null;

// apenas para escrever testes rápidos, por ora
public static void main(String[] args) {
String instituicaoDeEnsino;

public static int obterAnoCorrente() {
return Calendar.getInstance().get(Calendar.YEAR);
}

Aluno joao = new Aluno(1111, new String("João"));
Aluno maria = new Aluno(2222, "Maria");
private static int obterSemestreCorrente() {
return obterMesCorrente() <= 6 ? 1 : 2;
}

System.out.println("joao == maria? " + (joao == maria));
System.out.println("joao == joao? " + (joao == joao));
public static int obterMesCorrente() {
return Calendar.getInstance().get(Calendar.MONTH);
}

System.out.println("joao.equals(maria)? " + joao.equals(maria));
System.out.println("joao.equals(joao)? " + joao.equals(joao));
public static Periodo obterPeriodoCorrente() {

Aluno outroObjetoRepresentandoJoao = new Aluno(1111, new String("João"));
if (periodoCorrente != null) {
if (periodoCorrente.getAno() != obterAnoCorrente() ||
periodoCorrente.getSemestre() != obterSemestreCorrente()) {
periodoCorrente = null; // invalida o cache
}
}

System.out.println("joao == outroObjetoRepresentandoJoao? " +
(joao == outroObjetoRepresentandoJoao));
if (periodoCorrente == null) { // verifica o memo ("cache")
// atualiza o cache
periodoCorrente = new Periodo(obterAnoCorrente(), obterSemestreCorrente());
}

System.out.println("joao.equals(outroObjetoRepresentandoJoao)? " +
(joao.equals(outroObjetoRepresentandoJoao)));
return periodoCorrente;
}

// Aluno joao2 = new Aluno(1111, "João");
Aluno joao2;
joao2 = joao;
// apenas para escrever testes rápidos, por ora
public static void main(String[] args) {

System.out.println("joao2 == joao? " +
(joao2 == joao));
System.out.println("joao2.equals(joao)? " +
(joao2.equals(joao)));
System.out.println("Ano corrente = " + obterPeriodoCorrente());

Disciplina calculo1 = new Disciplina("Cálculo 1", 6, "MAA323");

MonitorDeDisciplina fulano;
fulano = new MonitorDeDisciplina();//1234, "Fulano de Tal", calculo1);

System.out.println("Aluno: " + fulano); // fulano.toString() será chamado automaticamente
}
}

0 comments on commit 95a11fc

Please sign in to comment.