Created
March 10, 2012 16:04
-
-
Save rodrigomanhaes/2011878 to your computer and use it in GitHub Desktop.
Soluções para a lista 2 de orientação a objetos (Java)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bin | |
.classpath | |
.project |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Collection; | |
import java.util.List; | |
public abstract class AbstractList<E> implements List<E> { | |
@Override | |
public boolean addAll(Collection<? extends E> c) { | |
for (E elem: c) | |
add(elem); | |
return true; | |
} | |
@Override | |
public boolean isEmpty() { | |
return size() == 0; | |
} | |
@Override | |
public boolean removeAll(Collection<?> c) { | |
for (Object o: c) | |
remove(o); | |
return true; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.junit.Assert.*; | |
import org.junit.Test; | |
public class AcademicoTest { | |
@Test | |
public void alunoSomentePodeIncluirDisciplinasComPreRequisito() { | |
Disciplina disciplinaPre = new Disciplina(20); | |
Disciplina disciplina = new Disciplina(15, disciplinaPre); | |
Aluno aluno = new Aluno(); | |
aluno.incluirNoPlano(disciplina); | |
assertFalse(aluno.planoOk()); | |
aluno = new Aluno(disciplinaPre); | |
aluno.incluirNoPlano(disciplina); | |
assertTrue(aluno.planoOk()); | |
} | |
@Test | |
public void planoDeveTerUmMinimoDe10EMaximoDe50Creditos() { | |
Disciplina disciplina1 = new Disciplina(9); | |
Disciplina disciplina2 = new Disciplina(1); | |
Disciplina disciplina3 = new Disciplina(40); | |
Disciplina disciplina4 = new Disciplina(1); | |
Aluno aluno = new Aluno(); | |
aluno.incluirNoPlano(disciplina1); | |
assertFalse(aluno.planoOk()); | |
aluno.incluirNoPlano(disciplina2); | |
assertTrue(aluno.planoOk()); | |
aluno.incluirNoPlano(disciplina3); | |
assertTrue(aluno.planoOk()); | |
aluno.incluirNoPlano(disciplina4); | |
assertFalse(aluno.planoOk()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.List; | |
public class Aluno { | |
private Plano plano; | |
private List<Disciplina> disciplinasCursadas; | |
public Aluno(Disciplina... disciplinas) { | |
plano = new Plano(this); | |
disciplinasCursadas = Arrays.asList(disciplinas); | |
} | |
public void incluirNoPlano(Disciplina disciplina) { | |
plano.incluir(disciplina); | |
} | |
public boolean planoOk() { | |
return plano.valido(); | |
} | |
public boolean cursou(List<Disciplina> disciplinas) { | |
for (Disciplina disciplina: disciplinas) | |
if (!disciplinasCursadas.contains(disciplina)) | |
return false; | |
return true; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Disciplina { | |
private int creditos; | |
private Disciplina preRequisito; | |
public Disciplina(int creditos, Disciplina preRequisito) { | |
this.creditos = creditos; | |
this.preRequisito = preRequisito; | |
} | |
public Disciplina(int creditos) { | |
this(creditos, null); | |
} | |
public int creditos() { | |
return creditos; | |
} | |
public Disciplina preRequisito() { | |
return preRequisito; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
public class Folha { | |
private List<Funcionario> funcionarios; | |
public Folha(Funcionario... funcionarios) { | |
this.funcionarios = Arrays.asList(funcionarios); | |
} | |
public Map<String, Double> calcular() { | |
Map<String, Double> resultado = new HashMap<String, Double>(); | |
for (Funcionario f : funcionarios) { | |
resultado.put(f.nome(), f.salarioAReceber()); | |
} | |
return resultado; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.junit.Assert.*; | |
import java.util.HashMap; | |
import java.util.Map; | |
import org.junit.Test; | |
public class FolhaTest { | |
@Test | |
public void retornaUmaListaDeFuncionariosESeusSalarios() { | |
Funcionario f1 = new Funcionario("Linus", 10000); | |
Funcionario f2 = new Funcionario("Guido", 8000); | |
Funcionario f3 = new Funcionario("Matz", 9000); | |
Folha folha = new Folha(f1, f2, f3); | |
Map<String, Double> esperado = new HashMap<String, Double>(); | |
esperado.put("Linus", 9280.0); | |
esperado.put("Guido", 7480.0); | |
esperado.put("Matz", 8380.0); | |
assertEquals(esperado, folha.calcular()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
public class Funcionario { | |
private String nome; | |
private double salarioTotal; | |
private int filhos; | |
private boolean gerente; | |
private boolean diretor; | |
private List<AlteracaoDeSalario> alteracoes; | |
public Funcionario(String nome, double salarioTotal) { | |
this(nome, salarioTotal, 0); | |
} | |
public Funcionario(String nome, double salarioTotal, int filhos) { | |
this.nome = nome; | |
this.salarioTotal = salarioTotal; | |
this.filhos = filhos; | |
this.gerente = false; | |
this.diretor = false; | |
this.alteracoes = new ArrayList<AlteracaoDeSalario>(); | |
this.alteracoes.add(new DescontoPrevidencia()); | |
this.alteracoes.add(new AdicionalGerente(this)); | |
this.alteracoes.add(new AdicionalDiretor(this)); | |
this.alteracoes.add(new AdicionalAuxilioCreche(this)); | |
this.alteracoes.add(new AdicionalAuxilioAlimentacao(this)); | |
} | |
public double salarioAReceber() { | |
double resultado = salarioTotal; | |
for (AlteracaoDeSalario adicional: adicionaisNaoIsentos()) | |
resultado = adicional.calcular(resultado); | |
for (AlteracaoDeSalario desconto: descontos()) | |
resultado = desconto.calcular(resultado); | |
for (AlteracaoDeSalario adicional: adicionaisIsentos()) | |
resultado = adicional.calcular(resultado); | |
return resultado; | |
} | |
private List<AlteracaoDeSalario> adicionaisNaoIsentos() { | |
List<AlteracaoDeSalario> resultado = new ArrayList<AlteracaoDeSalario>(); | |
for (AlteracaoDeSalario alteracao: alteracoes) | |
if (alteracao.eAdicional() && !((Adicional) alteracao).eIsento()) | |
resultado.add(alteracao); | |
return resultado; | |
} | |
private List<AlteracaoDeSalario> descontos() { | |
List<AlteracaoDeSalario> resultado = new ArrayList<AlteracaoDeSalario>(); | |
for (AlteracaoDeSalario alteracao: alteracoes) | |
if (!alteracao.eAdicional()) | |
resultado.add(alteracao); | |
return resultado; | |
} | |
private List<AlteracaoDeSalario> adicionaisIsentos() { | |
List<AlteracaoDeSalario> resultado = new ArrayList<AlteracaoDeSalario>(); | |
for (AlteracaoDeSalario alteracao: alteracoes) | |
if (alteracao.eAdicional() && ((Adicional) alteracao).eIsento()) | |
resultado.add(alteracao); | |
return resultado; | |
} | |
public void assumirGerencia() { | |
gerente = true; | |
} | |
public boolean eGerente() { | |
return gerente; | |
} | |
public void assumirDiretoria() { | |
diretor = true; | |
} | |
public boolean eDiretor() { | |
return diretor; | |
} | |
public double salarioTotal() { | |
return salarioTotal; | |
} | |
public String nome() { | |
return nome; | |
} | |
public int filhos() { | |
return filhos; | |
} | |
} | |
abstract class AlteracaoDeSalario { | |
public abstract boolean eAdicional(); | |
public abstract double calcular(double valor); | |
} | |
abstract class Desconto extends AlteracaoDeSalario { | |
@Override | |
public boolean eAdicional() { | |
return false; | |
} | |
} | |
class DescontoPrevidencia extends Desconto { | |
@Override | |
public double calcular(double valor) { | |
return valor * 0.9; | |
} | |
} | |
abstract class Adicional extends AlteracaoDeSalario { | |
protected Funcionario funcionario; | |
@Override | |
public boolean eAdicional() { | |
return true; | |
} | |
public boolean eIsento() { | |
return false; | |
} | |
} | |
class AdicionalGerente extends Adicional { | |
public AdicionalGerente(Funcionario funcionario) { | |
this.funcionario = funcionario; | |
} | |
@Override | |
public double calcular(double valor) { | |
return funcionario.eGerente() ? valor * 1.3 : valor; | |
} | |
} | |
class AdicionalDiretor extends Adicional { | |
public AdicionalDiretor(Funcionario funcionario) { | |
this.funcionario = funcionario; | |
} | |
@Override | |
public double calcular(double valor) { | |
return funcionario.eDiretor() ? valor * 1.4 : valor; | |
} | |
} | |
abstract class AdicionalIsento extends Adicional { | |
@Override | |
public boolean eIsento() { | |
return true; | |
} | |
} | |
class AdicionalAuxilioCreche extends AdicionalIsento { | |
public AdicionalAuxilioCreche(Funcionario funcionario) { | |
this.funcionario = funcionario; | |
} | |
@Override | |
public double calcular(double valor) { | |
int filhosParaCalculo = funcionario.filhos() > 3 ? 3 : funcionario.filhos(); | |
return valor + filhosParaCalculo * 400; | |
} | |
} | |
class AdicionalAuxilioAlimentacao extends AdicionalIsento { | |
public AdicionalAuxilioAlimentacao(Funcionario funcionario) { | |
this.funcionario = funcionario; | |
} | |
@Override | |
public double calcular(double valor) { | |
return valor + 280; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.junit.Assert.*; | |
import org.junit.Before; | |
import org.junit.Test; | |
public class FuncionarioTest { | |
private Funcionario funcionario; | |
private double alimentacao; | |
@Before | |
public void setup() { | |
funcionario = new Funcionario("Linus", 10000); | |
alimentacao = 280; | |
} | |
@Test | |
public void possuiNomeESalarioTotal() { | |
assertEquals("Linus", funcionario.nome()); | |
assertEquals(10000, funcionario.salarioTotal(), 0); | |
} | |
@Test | |
public void descontoDe10PorCentoDePrevidencia() { | |
assertEquals(9000, funcionario.salarioAReceber() - alimentacao, 0); | |
} | |
@Test | |
public void adicionalDe30PorCentroParaGerentes() { | |
funcionario.assumirGerencia(); | |
assertEquals(11700, funcionario.salarioAReceber() - alimentacao, 0); | |
} | |
@Test | |
public void adicionalDe40PorCentroParaDiretoria() { | |
funcionario.assumirDiretoria(); | |
assertEquals(12600, funcionario.salarioAReceber() - alimentacao, 0); | |
} | |
@Test | |
public void adicionalDe400PorFilhoAte3() { | |
assertEquals(1580, new Funcionario("Linus", 1000, 1).salarioAReceber(), 0); | |
assertEquals(1980, new Funcionario("Linus", 1000, 2).salarioAReceber(), 0); | |
assertEquals(2380, new Funcionario("Linus", 1000, 3).salarioAReceber(), 0); | |
assertEquals(2380, new Funcionario("Linus", 1000, 4).salarioAReceber(), 0); | |
} | |
@Test | |
public void adicionalAuxilioAlimentacaoDe280() { | |
assertEquals(9280, funcionario.salarioAReceber(), 0); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
import java.util.Map; | |
public class JogoDaVelha { | |
private Jogador[] jogadores; | |
private Map<Integer, Casa> casas; | |
private Status status; | |
private Jogador vez; | |
public JogoDaVelha() { | |
criarJogadores(); | |
criarCasas(); | |
distribuirCasas(); | |
inicializarFlags(); | |
} | |
private void criarJogadores() { | |
jogadores = new Jogador[] { Jogador.X, Jogador.Y }; | |
} | |
private void criarCasas() { | |
casas = new HashMap<Integer, Casa>(); | |
for (int i = 1; i <= 9; i++) | |
casas.put(i, new Casa(i)); | |
} | |
private void distribuirCasas() { | |
distribuir(Direcao.LINHA, 1, 2, 3); | |
distribuir(Direcao.LINHA, 4, 5, 6); | |
distribuir(Direcao.LINHA, 7, 8, 9); | |
distribuir(Direcao.COLUNA, 1, 4, 7); | |
distribuir(Direcao.COLUNA, 2, 5, 8); | |
distribuir(Direcao.COLUNA, 3, 6, 9); | |
distribuir(Direcao.DIAGONAL1, 1, 5, 9); | |
distribuir(Direcao.DIAGONAL2, 7, 5, 3); | |
} | |
private void distribuir(Direcao direcao, int indice1, int indice2, int indice3) { | |
Casa casa1 = casas.get(indice1); | |
Casa casa2 = casas.get(indice2); | |
Casa casa3 = casas.get(indice3); | |
casa1.proxima(direcao, casa2); | |
casa2.proxima(direcao, casa3); | |
casa3.proxima(direcao, casa1); | |
} | |
private void inicializarFlags() { | |
status = Status.EM_JOGO; | |
vez = jogadores[0]; | |
} | |
public void jogar(int numeroCasa) { | |
status = casas.get(numeroCasa).jogar(vez); | |
trocarVez(); | |
} | |
private void trocarVez() { | |
vez = vez == jogadores[0] ? jogadores[1] : jogadores[0]; | |
} | |
public boolean vitoria() { | |
return status == Status.VITORIA; | |
} | |
public boolean velha() { | |
for (Casa casa: casas.values()) | |
if (casa.vazia()) | |
return false; | |
return true; | |
} | |
} | |
enum Jogador { | |
X, Y; | |
} | |
enum Status { | |
EM_JOGO, | |
VITORIA; | |
} | |
enum Direcao { | |
LINHA, | |
COLUNA, | |
DIAGONAL1, | |
DIAGONAL2; | |
} | |
class Casa { | |
private int indice; | |
private Map<Direcao, Casa> vizinhos; | |
private Jogador jogador; | |
public Casa(int indice) { | |
this.indice = indice; | |
this.jogador = null; | |
this.vizinhos = new HashMap<Direcao, Casa>(); | |
} | |
public Status jogar(Jogador jogador) { | |
this.jogador = jogador; | |
return verificarJogada(); | |
} | |
public boolean vazia() { | |
return this.jogador == null; | |
} | |
private Status verificarJogada() { | |
return vitoria() ? Status.VITORIA : Status.EM_JOGO; | |
} | |
private boolean vitoria() { | |
for (Direcao direcao: Direcao.values()) { | |
Casa proxima = vizinhos.get(direcao); | |
if (proxima != null) | |
if (proxima.verificarVitoria(this, direcao)) | |
return true; | |
} | |
return false; | |
} | |
private boolean verificarVitoria(Casa origem, Direcao direcao) { | |
if (this == origem) | |
return true; | |
if (origem.jogador != jogador) | |
return false; | |
Casa proxima = vizinhos.get(direcao); | |
return proxima.verificarVitoria(origem, direcao); | |
} | |
public void proxima(Direcao direcao, Casa proxima) { | |
vizinhos.put(direcao, proxima); | |
} | |
@Override | |
public String toString() { | |
return "Casa" + indice; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.junit.Assert.*; | |
import org.junit.Before; | |
import org.junit.Test; | |
public class JogoDaVelhaTest { | |
private JogoDaVelha jogo; | |
@Before | |
public void setup() { | |
jogo = new JogoDaVelha(); | |
} | |
@Test | |
public void vitoriaCom3CasasDoMesmoJogadorNaMesmaLinha() { | |
for (int jogada: new int[] { 1, 4, 2, 5 }) { | |
jogo.jogar(jogada); | |
assertFalse(jogo.vitoria()); | |
} | |
jogo.jogar(3); | |
assertTrue(jogo.vitoria()); | |
} | |
@Test | |
public void vitoriaCom3CasasDoMesmoJogadorNaMesmaColuna() { | |
for (int jogada: new int[] { 1, 2, 4, 5 }) { | |
jogo.jogar(jogada); | |
assertFalse(jogo.vitoria()); | |
} | |
jogo.jogar(7); | |
assertTrue(jogo.vitoria()); | |
} | |
@Test | |
public void vitoriaCom3CasasDoMesmoJogadorNaDiagonal() { | |
for (int jogada: new int[] { 1, 2, 5, 3 }) { | |
jogo.jogar(jogada); | |
assertFalse(jogo.vitoria()); | |
} | |
jogo.jogar(9); | |
assertTrue(jogo.vitoria()); | |
} | |
@Test | |
public void vitoriaCom3CasasDoMesmoJogadorNaOutraDiagonal() { | |
for (int jogada: new int[] { 7, 2, 5, 4 }) { | |
jogo.jogar(jogada); | |
assertFalse(jogo.vitoria()); | |
} | |
jogo.jogar(3); | |
assertTrue(jogo.vitoria()); | |
} | |
@Test | |
public void velhaQuandoTodasAsCasasSaoPreenchidasSemVitoria() { | |
for (int jogada: new int[] { 1, 2, 3, 4, 8, 5, 6, 9 }) { | |
jogo.jogar(jogada); | |
assertFalse(jogo.vitoria()); | |
assertFalse(jogo.velha()); | |
} | |
jogo.jogar(7); | |
assertTrue(jogo.velha()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
import java.util.Map; | |
public class Maquina { | |
private String estado; | |
private Map<String, String[]> transicoes; | |
public Maquina(String estadoInicial) { | |
this.estado = estadoInicial; | |
this.transicoes = new HashMap<String, String[]>(); | |
} | |
public void transicao(String evento, String de, String para) { | |
transicoes.put(evento, new String[] { de, para }); | |
} | |
public void dispararEvento(String evento) { | |
String[] mudanca = transicoes.get(evento); | |
if (!estado.equals(mudanca[0])) | |
throw new TransicaoNegada(); | |
estado = mudanca[1]; | |
} | |
public String estado() { | |
return estado; | |
} | |
} | |
class TransicaoNegada extends RuntimeException { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.junit.Assert.*; | |
import org.junit.Before; | |
import org.junit.Test; | |
public class MaquinaTest { | |
private Maquina maquina; | |
@Before | |
public void criarMaquina() { | |
maquina = new Maquina("aberta"); | |
maquina.transicao("fechar", "aberta", "fechada"); | |
} | |
@Test | |
public void retornaEstado() { | |
assertEquals("aberta", maquina.estado()); | |
} | |
@Test | |
public void permiteMudancasDeEstadoDeAcordoComATransicao() { | |
maquina.dispararEvento("fechar"); | |
assertEquals("fechada", maquina.estado()); | |
} | |
@Test | |
public void negaMudancaDeEstadoSeOEstadoOrigemNaoForCorreto() { | |
maquina.transicao("abrir", "fechada", "aberta"); | |
try { | |
maquina.dispararEvento("abrir"); | |
fail("Nao deveria deixar abrir a partir do estado \"aberta\""); | |
} | |
catch (TransicaoNegada e) { | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
class Plano { | |
private static final int CREDITOS_MINIMOS = 10, CREDITOS_MAXIMOS = 50; | |
private List<Disciplina> disciplinas; | |
private Aluno aluno; | |
public Plano(Aluno aluno) { | |
this.aluno = aluno; | |
this.disciplinas = new ArrayList<Disciplina>(); | |
} | |
public void incluir(Disciplina disciplina) { | |
disciplinas.add(disciplina); | |
} | |
public boolean valido() { | |
return verificarPreRequisitos() && verificarNumeroDeCreditos(); | |
} | |
private boolean verificarPreRequisitos() { | |
List<Disciplina> preRequisitos = new ArrayList<Disciplina>(); | |
for (Disciplina d: disciplinas) | |
if (d.preRequisito() != null) | |
preRequisitos.add(d.preRequisito()); | |
return aluno.cursou(preRequisitos); | |
} | |
private boolean verificarNumeroDeCreditos() { | |
int creditos = 0; | |
for (Disciplina d: disciplinas) | |
creditos += d.creditos(); | |
return creditos >= CREDITOS_MINIMOS && creditos <= CREDITOS_MAXIMOS; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Collection; | |
import java.util.Iterator; | |
import java.util.List; | |
import java.util.ListIterator; | |
public class UENFList<E> extends AbstractList<E> { | |
private No<E> primeiro, ultimo; | |
public void adicionar(E elemento) { | |
if (primeiro == null) { | |
primeiro = new No<E>(elemento); | |
ultimo = primeiro; | |
} | |
else { | |
ultimo.proximo = new No<E>(elemento); | |
ultimo = ultimo.proximo; | |
} | |
} | |
public int quantidade() { | |
int quant = 0; | |
No<E> no = primeiro; | |
while (no != null) { | |
no = no.proximo; | |
quant++; | |
} | |
return quant; | |
} | |
public String toString() { | |
No<E> no = primeiro; | |
String result = ""; | |
while (no != null ) { | |
result += no.elemento; | |
no = no.proximo; | |
if (no != null) | |
result += ", "; | |
} | |
return result; | |
} | |
private class No<F> { | |
private F elemento; | |
private No<F> proximo; | |
public No(F elemento) { | |
this.elemento = elemento; | |
} | |
} | |
@Override | |
public boolean add(E e) { | |
adicionar(e); | |
return true; | |
} | |
@Override | |
public void add(int index, E element) { | |
No<E> no = primeiro; | |
for (int i = 0; i < index - 1; i++) | |
no = no.proximo; | |
No<E> aux = no.proximo; | |
no.proximo = new No<E>(element); | |
no.proximo.proximo = aux; | |
} | |
@Override | |
public boolean addAll(int index, Collection<? extends E> c) { | |
No<E> no = primeiro; | |
for (int i = 0; i < index - 1; i++) | |
no = no.proximo; | |
return false; | |
} | |
@Override | |
public void clear() { | |
primeiro = null; | |
ultimo = null; | |
} | |
@Override | |
public boolean contains(Object o) { | |
// TODO Auto-generated method stub | |
return false; | |
} | |
@Override | |
public boolean containsAll(Collection<?> c) { | |
// TODO Auto-generated method stub | |
return false; | |
} | |
@Override | |
public E get(int index) { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
@Override | |
public int indexOf(Object o) { | |
// TODO Auto-generated method stub | |
return 0; | |
} | |
@Override | |
public Iterator<E> iterator() { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
@Override | |
public int lastIndexOf(Object o) { | |
// TODO Auto-generated method stub | |
return 0; | |
} | |
@Override | |
public ListIterator<E> listIterator() { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
@Override | |
public ListIterator<E> listIterator(int index) { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
@Override | |
public boolean remove(Object o) { | |
// TODO Auto-generated method stub | |
return false; | |
} | |
@Override | |
public E remove(int index) { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
@Override | |
public boolean retainAll(Collection<?> c) { | |
// TODO Auto-generated method stub | |
return false; | |
} | |
@Override | |
public E set(int index, E element) { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
@Override | |
public int size() { | |
// TODO Auto-generated method stub | |
return 0; | |
} | |
@Override | |
public List<E> subList(int fromIndex, int toIndex) { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
@Override | |
public Object[] toArray() { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
@Override | |
public <T> T[] toArray(T[] a) { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.junit.Assert.*; | |
import java.util.List; | |
import org.junit.Test; | |
public class UENFListTest { | |
@Test | |
public void adicionaItens() { | |
UENFList<Integer> lista = new UENFList<Integer>(); | |
lista.adicionar(1); | |
lista.adicionar(2); | |
lista.adicionar(3); | |
assertEquals(3, lista.quantidade()); | |
assertEquals("1, 2, 3", lista.toString()); | |
} | |
@Test | |
public void implementaInterfaceList() { | |
List<Integer> lista = new UENFList<Integer>(); | |
lista.add(1); | |
lista.add(2); | |
lista.add(3); | |
lista.add(1, 4); | |
assertEquals("1, 4, 2, 3", lista.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment