Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a java Program for this Scenerio. Scenario Your client wants a family char

ID: 3833925 • Letter: W

Question

Write a java Program for this Scenerio.

Scenario Your client wants a family chart to be displayed which includes all the members of a family. Family details are given below and he want to do some processing on the data. The most appropriate data structure for showing the hierarchical relationship is Tree Represent a tree for the family chart given in Figure 1. Consider each node in the tree as a member of the family. Stage 3.1 Create the member class so that it has 1) a default constructor that initialises its attributes to sensible values. 2) a parameter constructor that sets all the attribute values based on the parameter values. 3) a setter method for each attribute. 4) a getter method for each attribute. 5) a toString method to return a suitably formatted string of the attribute values. Provide proper comments using Javadoc Stage 3.2 Using the DefaultMutableTreeNode where the user Object attribute refers to an riate nodes and link them to get the y member object, create a structure shown on Figurel. The y member details to be used are given on Table 1. Create a class called that makes use of recursion to list the family member as per their hierarchy in the console window, using tabulation to show the parent/cfiild relationships between nodes.Provide proper comments Stage 3.3 Create a class called DisplayTest002 that uses recursion to display all family members who lives in Dubai. Stage 3.4 Create a DefaultTreeModelobject, this tree model should contain the tree created in Stage 2. Add this tree model to a JTree and display the J Tree. Demonstrate this code with a class called Display est003

Explanation / Answer

public class TreeNode {

private String location;

private String surname;

private String parent;

private String forename;

private List<TreeNode> children;

  

public TreeNode(String location, String surname, String parent, String forename) {

this.location = location;

this.surname = surname;

this.parent = parent;

this.forename = forename;

}

public TreeNode() {

this.location = "";

this.surname = "";

this.parent = "";

this.forename = "";

children = new ArrayList<TreeNode>();

}

public void setLocation(String location) {

this.location = location;

}

public String getLocation() {

return location;

}

  

public void setSurname(String surname) {

this.surname = surname;

}

  

public String getSurname() {

return surname;

}

  

public void setParent(String parent) {

this.parent = parent;

}

  

public String getParent() {

return parent;

}

public void setForename(String forename) {

this.forename = forename;

}

public String getForename() {

return forename;

}

public void insert(TreeNode root, TreeNode newChild) {

if(root == null) {

root=newChild;

return;

}

if(root.forename==newChild.parent) {

root.children.add(newChild);

return;

}

for(TreeNode child : root.children) {

insert(child,newChild);

}

}

}

public class Test {

public static void main(String args[]) {

TreeNode root=null;

TreeNode temp=new TreeNode();

temp=new TreeNode("USA","Trump","Donald","Tiffany");

insert(root,temp);

}

void Displaytest001(TreeNode root) {

System.out.println("child is "+root.forename+" parent is "+root.parent);

for(TreeNode child : root.children) {

Displaytest001(child);

}

}

void Displaytest002(TreeNode root) {

if(root.location.equals("Dubai")) {

System.out.println("child is "+root.forename+" parent is "+root.parent);

}

for(TreeNode child : root.children) {

Displaytest002(child);

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote