Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. The Person class will be used to, obviously, define a person.
  2. String field name in public class Person in package oving3
  3. A Person has a name. Create a String-field to hold the name.
  4.  
  5. Person field mother in public class Person in package oving3
  6. A Person has a mother. Create a field for that, too.
  7.  
  8. Note that this is not a String field. Why? A Person's mother is also a Person! This gives you a taste of OOP. A class can actually hold fields of the same type as the class itself.
  9. Person field father in public class Person in package oving3
  10. Create a field for the father.
  11.  
  12. ArrayList<Person> field children in public class Person in package oving3
  13. An ArrayList holding the Person's children.
  14.  
  15. The children are naturally also Persons. Since person can have more than one, we cannot use a simple field, but need an ArrayList.
  16. public boolean method isMotherOf in public class Person in package oving3
  17. Create a method that tests whether this Person is the mother of the Person given as an argument to the method.
  18.  
  19. It is not enough to check whether the Person has this Person registered as his or her mother, you must check that the Person is in this Person's children list, too. Consistency is key here!
  20. public boolean method isFatherOf in public class Person in package oving3
  21. Create a method that tests whether this Person is the father of the Person given as an argument to the method.
  22.  
  23. public boolean method isSiblingOf in public class Person in package oving3
  24. Create a method that tests whether this Person is the sibling of the Person given as an argument to the method.
  25.  
  26. This method is actually a lot more subtle than it might seem at a first glance. Ask yourself; When are two people formally siblings? Furthermore, Java doesn't care whether or not a Person can be his/her own sibling in the real world. In Java, that is completely possible unless you force it not to be!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement