Skip to main content

more options

Answers to self-help exercise: Drawing objects

2. Draw an object for a class Person, which allows us to maintain a geneology tree for people. Person has three fields:

(1) name (a String).
(2) father (of class Person) null if unknown.
(3) mother (of class Person) null if unknown.

and the four methods:

(1) A function that yields the name of the person
(2) A function that yields the father of the person (null if unknown)
(3) A function that yields the mother of the person (null if unknown)
(4) A function with one parameter, of class Person, that yields true if the parameter is this person's father.

We chose the names of the fields and methods. We annotated each field with its type; you don't have to do this. With each method, we put the types of its parameters in parentheses. You don't have to do this now. You will learn more about parameters and their types later on.

asd