Guest User

Untitled

a guest
Jun 19th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. package line;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. public class Person{
  6.  
  7.     String name;
  8.     Person mother;
  9.     Person father;
  10.     ArrayList < Person > children = new ArrayList<Person>();
  11.    
  12.     public Person(){}
  13.    
  14.     public Person(String name) {
  15.         this.name = name;
  16.     }
  17.    
  18.     public boolean isMotherOf(Person person) {
  19.         Person name = person.mother;
  20.         if (name == this){
  21.             if (this.children.contains(person))
  22.                 return true;
  23.             else
  24.                 return false;
  25.         }
  26.         else
  27.             return false;
  28.     }
  29.     public boolean isFatherOf(Person person) {
  30.         Person name = person.father;
  31.         if (name == this){
  32.             if (this.children.contains(person))
  33.                 return true;
  34.             else
  35.                 return false;
  36.         }
  37.         else
  38.             return false;
  39.         }
  40.    
  41.     public boolean isSiblingOf(Person person){
  42.         if (person.mother == this.mother
  43.                 && person.father == this.father
  44.                 && this != person)
  45.             return true;
  46.         else
  47.             return false;
  48.     }
  49.     public String toString() {
  50.         String family = "";
  51.         if(!(this.name == null)){
  52.             family += "Name " + this.name;
  53.         }
  54.         if(this.mother != null && this.father != null) {
  55.             family += " mother: " + this.mother.name + " father: " + this.father.name;
  56.         }
  57.         if(!this.children.isEmpty()){
  58.             family += " children: ";
  59.             for (int i = 0 ; i < this.children.size(); i++) {
  60.                 family += this.children.get(i).name + " ";
  61.             }
  62.         }
  63.         return family;
  64.     }
  65. }
Add Comment
Please, Sign In to add comment