Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. package oving3;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import acm.program.ConsoleProgram;
  6.  
  7. /*
  8. * @startuml
  9. * class Person {
  10. * String name
  11. * Person mother
  12. * Person father
  13. * }
  14. * Person --> "*" Person : children
  15. * @enduml
  16. */
  17. public class Person extends ConsoleProgram {
  18. String name;
  19. Person mother, father;
  20.  
  21. ArrayList<Person> children = new ArrayList<Person>();
  22.  
  23.  
  24. public Person() {
  25.  
  26. }
  27.  
  28. public boolean isMotherOf(Person person){
  29. if(person.mother == null) return false;
  30. return person.mother == this && this.children.contains(person);
  31. }
  32.  
  33. public boolean isFatherOf(Person person){
  34. if(person.father == null) return false;
  35. return person.father == this && this.children.contains(person);
  36. }
  37.  
  38. public boolean isSiblingOf(Person person){
  39. if (this == person){
  40. return false;
  41. }
  42. else if (this.mother == person.mother && this.father == person.father){
  43. return true;
  44. }
  45. else {
  46. return false;
  47. }
  48. }
  49.  
  50.  
  51. public String toString(){
  52. String result = name ;
  53. String temp = "";
  54. int numberofkids = children.size();
  55. if(children.size() > 0){
  56. for (int i = 0; i < numberofkids; i++) {
  57. temp = temp + children.get(i).name + ", ";
  58. }
  59. }
  60. if (father != null){
  61. temp = temp + " Far: " + father.name;
  62. }
  63.  
  64. if (mother != null){
  65. temp = temp + " Mor: " + mother.name;
  66. }
  67. result = result + " har " + numberofkids + " barn; " + temp;
  68. return result;
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement