Yargi

FamilyTree 2/3

Oct 5th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3. import java.util.List;
  4.  
  5. public class Person {
  6.  
  7.     private final String name;
  8.     private final String birthDate;
  9.     private final List<Person> parents = new ArrayList<>();
  10.     private final List<Person> children = new ArrayList<>();
  11.  
  12.     public Person(String name, String birthDate){
  13.         this.name = name;
  14.         this.birthDate = birthDate;
  15.     }
  16.  
  17.     public String getName() {
  18.         return name;
  19.     }
  20.  
  21.     public String getBirthDate() {
  22.         return birthDate;
  23.     }
  24.  
  25.     public List<Person> getParents(){
  26.         return Collections.unmodifiableList(parents);
  27.     }
  28.  
  29.     public List<Person> getChildren() {
  30.         return Collections.unmodifiableList(children);
  31.     }
  32.  
  33.     public void addChild(Person child){
  34.         children.add(child);
  35.         child.parents.add(this);
  36.     }
  37.  
  38.     @Override
  39.     public String toString(){
  40.         return String.join(" ", name, birthDate);
  41.     }
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment