Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package packageProva;
- public class Rubrica {
- private String nome;
- private Voce[] voci;
- private int next;
- private final int MAX_VOCI = 100;
- public Rubrica(String nome) {
- this.nome = nome;
- this.voci = new Voce[MAX_VOCI];
- this.next = 0;
- }
- public String toString() {
- return "Nome rubrica: " + nome + " ";
- }
- public void aggiungi(String nome, String cognome, String numTelefono) {
- Voce temp = new Voce(nome, cognome, numTelefono);
- if (next < MAX_VOCI) {
- voci[next] = temp;
- next++;
- }
- }
- public String primo() {
- String output = "Rubrica vuota";
- if (next != 0) {
- output = "Primo: ";
- output += voci[0].toString();
- }
- return output;
- }
- public String voce(int indice) {
- String output;
- if (indice <= next)
- output = voci[indice-1].toString();
- else
- output = "Indice troppo grande";
- return output;
- }
- public String elenco() {
- String output = "Elenco: (";
- for( int i = 0; i < next; i++) {
- if (i != 0)
- output += ", ";
- output += voci[i].toString();
- }
- output += ")";
- return output;
- }
- public String ricerca(String strDaCercare) {
- String output = "Trovato: ";
- for(int i=0; i <=next; i++) {
- if (voci[i].getNome().contains(strDaCercare) || voci[i].getCognome().contains(strDaCercare)
- || voci[i].getNumTelefono().contains(strDaCercare)) {
- output += voci[i].toString();
- break;
- }
- }
- return output;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement