Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In java, I bolded my error in my code, it is in the FTree class and maybe PPerson class (I bolded this one too). Here

In java,

I bolded my error in my code, it is in the FTree class and maybe PPerson class (I bolded this one too).

Here is what the complier said:

error: cannot find symbol boolean relativeFound = PreorderTraversal(p1, personsTraversed, false, false); symbol: variable p1 location: class FTree

FTree class:

import java.util.*; import java.util.ArrayList;

public class FTree { //public data members public ArrayList Families; public PPerson Relative; //public methods //default constructors public FTree() { Families = new ArrayList(); } //add new person to the family tree public boolean Add(PPerson p) { if(!Families.contains(p)) { Families.add(p); return true; } return false; } public void FindRelation(PPerson pl, PPerson p2) { //perform pre-order traversal of family tree starting with Person p1 Relative = p2;

ArrayList personsTraversed = new ArrayList<>(); //my teacher wrote the tilde in the diamond but idk what it means " ArrayList personsTraversed = new ArrayList<~>(); " boolean relativeFound = PreorderTraversal(p1, personsTraversed, false, false); for(int i=0; i personsTraversed , boolean isPartner, boolean isChild , int level) { //recursion terminating condition if(p == null) return false; if(personsTraversed.contains(p)) return false; personsTraversed.add(p); String gender = p.IsMale ? " (Male)" : " (Female)"; String partnerStr = isPartner ? " (Partner)" : ""; String childStr = isChild ? " (Child)" : ""; String displayName = ""; for(int j=0; j

PPerson class:

import java.util.*; import java.util.ArrayList;

public class PPerson { //public data member public String Name; public String DOB; public boolean IsMale; public PPerson Mother; public PPerson Father; public ArrayList Partners; public ArrayList Children; public String DisplayName; //public methods //default constructor public PPerson() { InIt(false, "", "1/1/1900"); } public PPerson(boolean isMale, String name, String dob) { InIt(isMale, name, dob); } public PPerson(boolean isMale, String name, PPerson father, PPerson mother) { InIt(isMale, name, ""); AddParent(father, false); AddParent(mother, true); } //initialize data members private void InIt(boolean isMale, String name, String dob) { Name = name; DOB = dob; IsMale = isMale; Partners = new ArrayList(); Children = new ArrayList(); }

public void AddParent(PPerson parent, boolean isMother) { if(isMother) { this.Mother = parent; } else { this.Father = parent; } } //add partner to person's partner collection public boolean AddPartner(PPerson partner) { boolean result = false; if(!Partners.contains(partner)) { Partners.add(partner); return true; } if(!partner.Partners.contains(this)) { partner.Partners.add(this); } return result; } //add child to person's children collection public boolean AddChild(PPerson child) { if(!Children.contains(child)) { Children.add(child); return true; } return false; }

//display all persons related to this person //perform preorder traversal of family tree starting from current person public void Display() { //perform preorder traversal of family tree starting from current person ArrayList personsTraversed = new ArrayList<>();

// my teacher wrote, again with a tilde(~) " ArrayList personsTraversed = new ArrayList<~>(); " PreOrderDisplay(this, personsTraversed, false, false, 0); } private void PreOrderDisplay(PPerson p, ArrayList personTraversed, boolean isPartner, boolean isChild, int level) { //recursion terminating condition if(p == null) return; if(personTraversed.contains(p)) return; personTraversed.add(p); String gender = p.IsMale ? " (Male) " : " (Female)"; String partnerStr = isPartner ? " (Partner)" : ""; String childStr = isChild ? " (Child)" : ""; /* if(isPartner || isChild) System.out.print("-"); */ for(int j=0; j

} }

Test class:

public class Test { public static void main(String[] args) { FTree myFamily = new FTree(); PPerson johnDoe = new PPerson(true, "John Doe", ""); myFamily.Add(johnDoe); PPerson maryJane = new PPerson(false, "Mary Jane", ""); johnDoe.AddPartner(maryJane); maryJane.AddChild(new PPerson(true, "Jim Doe", johnDoe, maryJane)); PPerson jennDoe = new PPerson(false, "Jennifer Doe", johnDoe, maryJane); maryJane.AddChild(jennDoe); PPerson timClark = new PPerson(true, "Tim Clark", ""); jennDoe.AddPartner(timClark); PPerson jessClark = new PPerson(false, "Jesse Clark", timClark, jennDoe); jennDoe.AddChild(jessClark); PPerson nicoleDoe = new PPerson(false, "Nicole Doe", ""); johnDoe.AddPartner(nicoleDoe); PPerson nickJonah = new PPerson(true, "Nick Jonah", ""); nicoleDoe.AddPartner(nickJonah); nicoleDoe.AddChild(new PPerson(false, "Nancy Jonah", nickJonah, nicoleDoe)); johnDoe.Display(); myFamily.FindRelation(nickJonah, jessClark); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions

Question

7. What is coaching? Is there only one type of coaching? Explain.

Answered: 1 week ago