Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vitorpiovezam/7009ca876aff038d91435e946b47f171 to your computer and use it in GitHub Desktop.
Save vitorpiovezam/7009ca876aff038d91435e946b47f171 to your computer and use it in GitHub Desktop.
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Disciplina {
private String nome;
private String professor;
private List<Aula> listaAula = new ArrayList<>();
private Map<Integer,Aluno> listaAluno = new HashMap<>();
public Disciplina(String nome, String professor) {
super();
this.nome = nome;
this.professor = professor;
}
public void matricular(Aluno aluno){
listaAluno.put(aluno.getRm(), aluno);
}
}
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class Teste {
public static void main(String[] args) {
/*Set<Aluno> lista = new HashSet<>();
lista.add(new Aluno (58,"abacate"));
lista.add(new Aluno (987,"uva"));
lista.add(new Aluno (236,"abacaxi"));
lista.add(new Aluno (10,"jaca"));
lista.add(new Aluno (57,"uva"));*/
Map<Integer, Aluno> lista = new HashMap<>();
lista.put(58, new Aluno (58,"abacate"));
lista.put(987, new Aluno (987,"uva"));
lista.put(10, new Aluno (10, "jaca"));
lista.put(987, new Aluno (987,"uva"));
System.out.println(lista);
System.out.println(lista.get(987));
System.out.println(lista.containsKey(987));
}
}
public class Aula {
private String topico;
private int duracao;
public Aula(String topico, int duracao) {
this.topico = topico;
this.duracao = duracao;
}
public int getDuracao() {
return duracao;
}
public String getTopico() {
return topico;
}
}
public class Aluno implements Comparable<Aluno> {
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((nome == null) ? 0 : nome.hashCode());
result = prime * result + rm;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Aluno other = (Aluno) obj;
if (nome == null) {
if (other.nome != null)
return false;
} else if (!nome.equals(other.nome))
return false;
if (rm != other.rm)
return false;
return true;
}
private int rm;
private String nome;
public Aluno(int rm, String nome) {
this.rm = rm;
this.nome = nome;
}
@Override
public String toString() {
return rm+"-"+nome;
}
@Override
public int compareTo(Aluno aluno) {
return this.nome.compareTo(aluno.getNome());
}
public String getNome() {
return nome;
}
public int getRm() {
return rm;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment