Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. import java.util.Arrays;
  2. public class Vetor {
  3.     private Aluno[] alunos = new Aluno[10];
  4.     private int totalDeAlunos = 0;
  5.     public void adiciona(Aluno aluno) {
  6.     this.alunos[this.totalDeAlunos] = aluno;
  7.     this.totalDeAlunos++;
  8. }
  9.    
  10.     public void adiciona(int posicao, Aluno aluno) {
  11. alunos[posicao] = aluno;
  12. }
  13.  
  14.   public Aluno pega(int posicao) {
  15. return this.alunos[posicao];
  16. }
  17.     public void remove(int posicao) {
  18.         alunos[posicao] = null;
  19.     }
  20.     public boolean contem(Aluno aluno) {
  21. for (int i = 0; i < this.totalDeAlunos; i++) {
  22. if (aluno.equals(this.alunos[i])) {
  23. return true;
  24. }
  25. }
  26. return false;
  27. }
  28.  
  29.  
  30.     public int tamanho() {
  31.     return this.totalDeAlunos;
  32. }
  33.  
  34.     public String toString() {
  35.         return Arrays.toString(alunos);
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement