Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Attrezzo {
- private String nome;
- public Attrezzo(String nomeAttrezzo){
- this.nome = nomeAttrezzo;
- }
- public String getNome() {return this.nome; }
- }
- public class Borsa{
- private Attrezzo[] attrezzi;
- public Borsa(){
- Attrezzo chiave = new Attrezzo("chiave");
- Attrezzo pialla = new Attrezzo("pialla");
- Attrezzo scala = new Attrezzo("scala");
- Attrezzo smartphone = new Attrezzo("smartphone");
- this.attrezzi = new Attrezzo[]{chiave, pialla, scala, smartphone};
- }
- public Attrezzo cercaAttrezzo(String nomeAttrezzo){
- for(Attrezzo attrezzo: this.attrezzi)
- if(attrezzo.getNome().equals(nomeAttrezzo))
- return attrezzo;
- return null;
- }
- public static void main(String[] args){
- Borsa borsa = new Borsa();
- Attrezzo trovato = borsa.cercaAttrezzo("portafogli");
- System.out.println(trovato.getNome());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement