Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package line;
- import java.util.ArrayList;
- public class Person{
- String name;
- Person mother;
- Person father;
- ArrayList < Person > children = new ArrayList<Person>();
- public Person(){}
- public Person(String name) {
- this.name = name;
- }
- public boolean isMotherOf(Person person) {
- Person name = person.mother;
- if (name == this){
- if (this.children.contains(person))
- return true;
- else
- return false;
- }
- else
- return false;
- }
- public boolean isFatherOf(Person person) {
- Person name = person.father;
- if (name == this){
- if (this.children.contains(person))
- return true;
- else
- return false;
- }
- else
- return false;
- }
- public boolean isSiblingOf(Person person){
- if (person.mother == this.mother
- && person.father == this.father
- && this != person)
- return true;
- else
- return false;
- }
- public String toString() {
- String family = "";
- if(!(this.name == null)){
- family += "Name " + this.name;
- }
- if(this.mother != null && this.father != null) {
- family += " mother: " + this.mother.name + " father: " + this.father.name;
- }
- if(!this.children.isEmpty()){
- family += " children: ";
- for (int i = 0 ; i < this.children.size(); i++) {
- family += this.children.get(i).name + " ";
- }
- }
- return family;
- }
- }
Add Comment
Please, Sign In to add comment