Advertisement
piffy

4.1.13 Es 6

Aug 29th, 2021
1,422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. public class Persona {
  2.    
  3.     /**
  4.      * I commenti indicano la sequenza in cui dovreste aver scritto
  5.      * il codice, se avete seguito rigorosamente il TDD.
  6.      */
  7. private String nome,oggetto;
  8.  
  9. //1° test
  10. public Persona(String nome, String oggetto) {
  11.         super();
  12.         this.nome = nome;
  13.         this.oggetto = oggetto;
  14.     }
  15.  
  16. //2° test
  17. public String getOggetto() {
  18.     return oggetto;
  19. }
  20.  
  21. //3° test
  22. public String getNome() {
  23.     return nome;
  24. }
  25.  
  26. //1° test
  27. @Override
  28. public String toString() {
  29.     return nome + " preferisce il " + oggetto;
  30. }
  31.  
  32. //2° test
  33. public boolean isCompatibile(Persona p1) {
  34.     return oggetto.equals(p1.getOggetto());
  35. }
  36.  
  37. //3° test
  38. @Override
  39. public boolean equals(Object p) {
  40.     if (! (p instanceof Persona))
  41.         return false;
  42.     Persona p1= (Persona) p;
  43.     return oggetto.equals(p1.getOggetto()) &&
  44.             nome.equals(p1.getNome());
  45. }
  46.  
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement