Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- public class Person {
- private final String name;
- private final String birthDate;
- private final List<Person> parents = new ArrayList<>();
- private final List<Person> children = new ArrayList<>();
- public Person(String name, String birthDate){
- this.name = name;
- this.birthDate = birthDate;
- }
- public String getName() {
- return name;
- }
- public String getBirthDate() {
- return birthDate;
- }
- public List<Person> getParents(){
- return Collections.unmodifiableList(parents);
- }
- public List<Person> getChildren() {
- return Collections.unmodifiableList(children);
- }
- public void addChild(Person child){
- children.add(child);
- child.parents.add(this);
- }
- @Override
- public String toString(){
- return String.join(" ", name, birthDate);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment