PRO_gramer

Untitled

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