-
Notifications
You must be signed in to change notification settings - Fork 0
/
List.java
82 lines (79 loc) · 1.88 KB
/
List.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package ArrayList;
/**
* Programa que usa uma ArrayList para guardar os nomes
* dos professores.
* Permite a utilização de vários métodos nessa
* ArrayList.
*
* @author
* @version 1.0
*/
import java.util.*;
import static java.lang.System.out;
public class List
{
//Declaração da ArrayList
ArrayList<String> professores = new ArrayList<String>();
//Adiciona 3 professores à lista
public void adicionaProfs()
{
professores.add("Jorge");
professores.add("Paulo");
professores.add("Silvio");
out.println("Foram adicionados automaticamente 3 professores");
out.println("==============================================");
}
//Adiciona à lista um professor com nome definido pelo utilizador
public void criarNovoProf(String nome)
{
professores.add(nome);
out.println ("Foi adicionado um professor com o nome "+nome);
out.println ("===========================================");
}
public void listarProfessores()
{
out.println("Lista de Professores");
for (String nome : professores)
out.println(nome);
out.println("========================================");
}
public void tamanhoDaLista()
{
int a = professores.size();
out.println("A lista tem "+a+" elementos");
out.println("==========================");
}
public void existe(String nome)
{
int i=0;
for (String profs : professores)
{
if (profs.contains(nome)==true)
{
i++;
}
}
if (i==0)
out.println("Não Existe");
if (i>0)
out.println("Foram encontradas "+i+" ocorrencias do nome "+nome);
out.println("=================================================");
}
public void apagarTudo()
{
professores.clear();
out.println("Todos os registos foram apagados");
}
public void apagaElemento(String nome)
{
professores.remove(nome);
}
public void verificarVazio()
{
if (professores.isEmpty()==true)
out.println("Está Vazio");
else if (professores.isEmpty()==false)
out.println("Não está vazio");
}
}
//Bom, espero que tenham gostado, dúvidas e questões nos comentários. Obrigado.