Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For this project you will create a recursive data structure to hold your family tree ( use ANY tree data structure you want ) .
For this project you will create a recursive data structure to hold your family tree use ANY tree data structure you want It doesnt have to be your family, any family of your choosing you could use The Simpsons or another family We will represent a family by creating a Person object. The Person object should have at least three fields: name, mom, and dad. Each of the mom and dad fields will either be null or will point to another Person object which is what makes it recursive For example, you might create objects like the following example:
Person me new PersonSarah Jessica Parker;
medad new PersonFather Parker;
memom new PersonMother Parker;
memom.dad new PersonGrandfather on Mom's side;
Make a family tree with at least four generations, even if you have to make up people. Connect all of the people in your tree in the appropriate manner. To do this, you can add additional methods to your class. For example, you might want to have a method that works like this:
meaddParentsJohn SmithJane Doe;
That could be implemented like so:
class Person
Person mom;
Person dad;
void addParentsString fathername, String mothername
this.dad new Personfathername;
You could write a recursive function to count how many people are in your tree like so:
class Person
int count
int sum ; that is you!
if mom null
sum mom.count;
if dad null
sum dad.count;
return sum;
System.out.printlnThe tree has mecount people in it;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started