Question

In BlueJ using Java, write a program that can input and display a person’s family tree....

In BlueJ using Java, write a program that can input and display a person’s family tree. This project requires a GUI class that allows the user to input the members of the family tree and print the family tree.

0 0
Add a comment Improve this question Transcribed image text
Answer #1


public class FTree
{
private class Node
{
String value;
Node left, right;

Node(String val)
{
value = val;
left = null;
right = null;
}

Node(String val, Node lChild, Node rChild)
{
value = val;
left = lChild;
right = rChild;
}
}

private Node root = null;

public boolean root(String x)
{
if (root == null){
root = new Node(x);
return true;}
else
return false;
}

public boolean addLeft(String p, String x)
{
Node parent = locate(p);
if (root == null ){
return false;}
else if (parent != null && parent.left == null){
parent.left = new Node(x);
return true;}
else
return false;
}

public boolean addRight(String p, String x)
{
Node parent = locate(p);
if (root == null ){
return false;}
else if (parent != null && parent.right == null){
//Adds node
parent.right = new Node(x);
return true;}
else
return false;
}

public Node locate(String p)
{
return locate(p, root);
}

private Node locate(String p, Node familyTree)
{
Node result = null;
if (familyTree == null)
return null;
if (familyTree.value.equals(p))
return familyTree;
if (familyTree.left != null)
result = locate(p,familyTree.left);
if (result == null)
result = locate(p,familyTree.right);
return result;
}

}


Add a comment
Know the answer?
Add Answer to:
In BlueJ using Java, write a program that can input and display a person’s family tree....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT