Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. package packageProva;
  2.  
  3. public class Rubrica {
  4.  
  5. private String nome;
  6.  
  7. private Voce[] voci;
  8.  
  9. private int next;
  10.  
  11. private final int MAX_VOCI = 100;
  12.  
  13. public Rubrica(String nome) {
  14. this.nome = nome;
  15. this.voci = new Voce[MAX_VOCI];
  16. this.next = 0;
  17. }
  18.  
  19. public String toString() {
  20.  
  21. return "Nome rubrica: " + nome + " ";
  22. }
  23.  
  24. public void aggiungi(String nome, String cognome, String numTelefono) {
  25. Voce temp = new Voce(nome, cognome, numTelefono);
  26. if (next < MAX_VOCI) {
  27. voci[next] = temp;
  28. next++;
  29. }
  30.  
  31. }
  32.  
  33. public String primo() {
  34. String output = "Rubrica vuota";
  35.  
  36. if (next != 0) {
  37. output = "Primo: ";
  38. output += voci[0].toString();
  39. }
  40.  
  41. return output;
  42. }
  43.  
  44. public String voce(int indice) {
  45. String output;
  46.  
  47. if (indice <= next)
  48. output = voci[indice-1].toString();
  49. else
  50. output = "Indice troppo grande";
  51.  
  52. return output;
  53. }
  54.  
  55. public String elenco() {
  56. String output = "Elenco: (";
  57.  
  58. for( int i = 0; i < next; i++) {
  59. if (i != 0)
  60. output += ", ";
  61. output += voci[i].toString();
  62. }
  63.  
  64. output += ")";
  65.  
  66. return output;
  67. }
  68.  
  69. public String ricerca(String strDaCercare) {
  70. String output = "Trovato: ";
  71.  
  72. for(int i=0; i <=next; i++) {
  73. if (voci[i].getNome().contains(strDaCercare) || voci[i].getCognome().contains(strDaCercare)
  74. || voci[i].getNumTelefono().contains(strDaCercare)) {
  75. output += voci[i].toString();
  76. break;
  77. }
  78. }
  79. return output;
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement