Part two of my assignment
Person class
Create the class Person in package oving2 with the following fields:
public String name
The name field holds the person's name.
public Person mother
The mother field holds a reference to the person's mother.
public Person father
The father field holds a reference to the person's father.
public Person[] children
The children field holds a reference to an array of the person's children.
This one is ok I think...
-
public class Person {
-
public String name;
-
public Person mother;
-
public Person father;
-
public Person[]children;
Part 2.2: The Royal Family
Implement the following method in the Person class:
public static Person createRoyalFamily()
This method should create an object graph corresponding to the royal family descending from King Harald and Queen Sonja.
The royal family consists of Harald, Sonja, their children Haakon and Martha. Haakon has two children with Mette-Marit named Ingrid Alexandra and Sverre Magnus, and Martha has two children with Ari named Maud Angelica and Leah Isadora.
The createRoyalFamily method must create Person objects corresponding to all member of the Royal family, and correctly set their name, mother, father, and children fields. Finally, the Person object corresponding to King Harald must be returned.
Note that the createRoyalFamily method must be declared static, since it will be called without any reference to any Person object.
Part 2.3: Family relations
Implement the following methods in the Person class:
public boolean isMotherOf(Person)
a method returns whether this Person is the mother of the Person given as parameter.
public boolean isFatherOf(Person)
a method returns whether this Person is the father of the Person given as parameter.
public boolean isSiblingOf(Person)
a method returns whether this Person is a sibling of the Person given as parameter.
public boolean isHalfSiblingOf(Person)
a method returns whether this Person is a half sibling of the Person given as parameter. A person is another person's half sibling if they have the same mother or father but not both.
Would be nice with som tips and hints on the different parts of this one..