Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package oving3;
- import java.util.ArrayList;
- import acm.program.ConsoleProgram;
- /*
- * @startuml
- * class Person {
- * String name
- * Person mother
- * Person father
- * }
- * Person --> "*" Person : children
- * @enduml
- */
- public class Person extends ConsoleProgram {
- String name;
- Person mother, father;
- ArrayList<Person> children = new ArrayList<Person>();
- public Person() {
- }
- public boolean isMotherOf(Person person){
- if(person.mother == null) return false;
- return person.mother == this && this.children.contains(person);
- }
- public boolean isFatherOf(Person person){
- if(person.father == null) return false;
- return person.father == this && this.children.contains(person);
- }
- public boolean isSiblingOf(Person person){
- if (this == person){
- return false;
- }
- else if (this.mother == person.mother && this.father == person.father){
- return true;
- }
- else {
- return false;
- }
- }
- public String toString(){
- String result = name ;
- String temp = "";
- int numberofkids = children.size();
- if(children.size() > 0){
- for (int i = 0; i < numberofkids; i++) {
- temp = temp + children.get(i).name + ", ";
- }
- }
- if (father != null){
- temp = temp + " Far: " + father.name;
- }
- if (mother != null){
- temp = temp + " Mor: " + mother.name;
- }
- result = result + " har " + numberofkids + " barn; " + temp;
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement