Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- public class Vetor {
- private Aluno[] alunos = new Aluno[10];
- private int totalDeAlunos = 0;
- public void adiciona(Aluno aluno) {
- this.alunos[this.totalDeAlunos] = aluno;
- this.totalDeAlunos++;
- }
- public void adiciona(int posicao, Aluno aluno) {
- alunos[posicao] = aluno;
- }
- public Aluno pega(int posicao) {
- return this.alunos[posicao];
- }
- public void remove(int posicao) {
- alunos[posicao] = null;
- }
- public boolean contem(Aluno aluno) {
- for (int i = 0; i < this.totalDeAlunos; i++) {
- if (aluno.equals(this.alunos[i])) {
- return true;
- }
- }
- return false;
- }
- public int tamanho() {
- return this.totalDeAlunos;
- }
- public String toString() {
- return Arrays.toString(alunos);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement