Advertisement
Fabioux

Untitled

Jan 22nd, 2022
889
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. class Attrezzo {
  2.     private String nome;
  3.     public Attrezzo(String nomeAttrezzo){
  4.         this.nome = nomeAttrezzo;
  5.     }
  6.     public String getNome() {return this.nome; }
  7. }
  8.  
  9. public class Borsa{
  10.     private Attrezzo[] attrezzi;
  11.    
  12.     public Borsa(){
  13.         Attrezzo chiave = new Attrezzo("chiave");
  14.         Attrezzo pialla = new Attrezzo("pialla");
  15.         Attrezzo scala = new Attrezzo("scala");
  16.         Attrezzo smartphone = new Attrezzo("smartphone");
  17.         this.attrezzi = new Attrezzo[]{chiave, pialla, scala, smartphone};
  18.     }
  19.    
  20.     public Attrezzo cercaAttrezzo(String nomeAttrezzo){
  21.         for(Attrezzo attrezzo: this.attrezzi)
  22.         if(attrezzo.getNome().equals(nomeAttrezzo))
  23.         return attrezzo;
  24.         return null;
  25.     }
  26.    
  27.     public static void main(String[] args){
  28.        
  29.         Borsa borsa = new Borsa();
  30.         Attrezzo trovato = borsa.cercaAttrezzo("portafogli");
  31.        
  32.         System.out.println(trovato.getNome());
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement