How To Program Family Tree
May 7, 2015I have to write a program that will input and display a person's family tree. I'm using BlueJ.
View RepliesI have to write a program that will input and display a person's family tree. I'm using BlueJ.
View RepliesI am to design a program in java that will allow a user to Input a list of your family members along with their age and state where they reside. Determine and print the average age of your family and print the names of anyone who live in Texas. I have tried but my results are wrong.
View Replies View RelatedThe problem I'm having is when the text box pops up and ask to start with a root name, I cannot enter anything and I am not sure what I have done wrong.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class FamilyTreeDemo extends JFrame
[Code] ....
How to do draw the original binary tree based on traversal results?
A binary tree has this pre-order traversal result: A,B,D,H,I,E,F,C,G,K,J (TreeNodes) And the same tree gives the following in-order traversal: B,H,I,D,A,C,F,E,K,G,J. Can you draw the tree structure?
We have this piece of code and we must make a search for a key. if the key exist it returns true if not false. Plus we must insert a key in the class. If it is already in there we say hey its already in and we don t put it again...
package askisi2;
import java.util.*;
public class mtree {
protected class tnode {
public int k1;
public int k2;
public int k3;
[Code] ....
So everything in my program is working EXCEPT when it comes to calculating the result. I am supposed to evaluate the expression using postorder traversal to return the answer. I am honestly not sure how I would get the postorder traversal to return the answer to the expression since the only thing we really went over was how it re-ordered the expression so that it would end in the postorder/postfix order. Anyways, currently the way that I have the public int evaluate(Node node)method set up is giving me a result of 0, which obviously is not correct.
Here's the section that I'm having issues with:
public int evaluate(Node node){
if(node.isLeaf()){
return Integer.parseInt(node.value);
}
int result = 0;
int left = evaluate(node.left);
int right = evaluate(node.right);
[code]....
how to create a tree data structure in java.I tried with a class consisting of node field and arraylist child nodes. but it does not satisfy the requirement.the requirement is that,
root: child1,child2,child3
child1:child4,child5
child2:child6,child7
on traversing it should print all the nodes as given above.no node should have same elements as child.
I have been trying to make a good tree structure for my Electrical Distribution network.. How to create two "subfolder" of my Voltage level folder.
Here is the code
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JApplet;
import javax.swing.JButton;
[Code] ....
I'm trying to write Java code for the following figure. Where, if node:4 will create following separate 4 trees. Number of node in
LEVEL1 (yellow) : n node.
LEVEL2 (green) : n-1 node.
LEVEL3 (blue) : n-2 node.
See image for node:4.
4node.jpg
The example out for node:4 :
012
013
021
023
031
032 and so on.
I know what the tree data structure is, how it works, etc., but I need to design a method that will sequentially print out all the paths in the tree (i.e. for each node).
The method as provided is
private static String getAllPaths(final BinaryNodeInterface<Character> root) { }
Now the string that must be returned needs to be of the format:
root.getData() + " " + path + "
"
root.getData()[1] + " " + path[1] + "
"
etc.
The pseudocode I was thinking of doing was something along the lines of:
paths
if(root.getData() = null) return paths;
path = ?; // absolutely no clue what to do here
paths += root.getData() + " " + path + "
";
if(root.hasLeftChild()) {
newPath += "0";
paths += begin recursion;
}
if(root.hasRightChild()) {
newPath += "1";
paths += begin recursion;
}
return paths;
Problems:
(1) I don't know how to determine "path" before the left and right children check (the root node's path is "", the first left node's path is "0", the first right node's path is "1", pattern continues with left being "0" and right being "1").
(2) I don't know where to put newlines precisely.
(3) I'm not sure how to get the print layout precisely as it is supposed to be. At most I've been able to just get the last number in the sequence (i.e. if it was supposed to be "1000", I could get "0".
I am working with the pseudocode formulation, especially in regards to the logic and formatting. I think once I have an understanding of what is going on, I can solve it. And yes, I've gone through a couple pseudocode rewrites (a few hours worth) and haven't gotten anywhere which is slightly unnerving.
As one of the methods of my IntTree tree I have to implement a method that multiplies the level number with the sum of the nodes on the current level. So far I have this, and it doesn't work. What I am wondering is am I on the right track at all with the second return statement?
public int depthSum(){
return depthSum(overallRoot);
}
private int depthSum(IntTreeNode root) {
if(root==null)
return 0;
int level = 0;
[code]....
I have a list of people with a matching telephone extension number, the people are organised in a hierachy tree with some colleagues at the same level and then some junior colleagues. I have been trying to write code that can find the tree height of any given member but I am unable too. Here is my code so far but the left and right are not working because I have not declared them any where in my code.
Java Code:
//hierarchy rank section 7
// **Depth** from node to root (bottom up)
public int rank(Member p1){
//to do
[code]....
My task is to implement a B-Tree data structure in Java using no libraries.
My current problem is inserting when the root is full, thus the middle key goes to root.keys[0] and then it get the left and right side which are new Nodes separating and inserting their keys. My problem is that for some reason there is a random second number when in the root and secondly my boolean leaf is always false meaning it never detects that the Tree is deeper than root.
The coding makes sense to me and I have tried printing everywhere but still can't seem to find the problem.
public class BTree {
/*
1. You may not modify the public interface of this class. You may however add any additional methods and/or field which you may require to aid you in the completion of this assignment.
2. You will have to design and implement a Node class. The BTree should house Integer objects.
3. You will notice that there are some overloaded methods, some of which work for Integer objects and some with primitive type int. You have to find a way to implement the methods to work with both types.
*/
class BTreeNode {
boolean leaf = true;
int numKeys = 1;
int mOrder;
Integer keys[];
[Code] ....
I am new to java. is there any possibility to store parse tree in database such as mqsql, oracle, etc. My requirement is [URL] ..... I found some code about generating parse tree. my next step is store that tree in database.
View Replies View RelatedThis is probably more of a web-based question. I have a basic web crawler I wrote with Java (using JSoup) which crawls through our repositories and stuff to locate the paths to certain snapshots and whatnot. It crawls through using the file tree which gets exposed when you try to go to a directory in a URL.
The problem I am having is that some of the directories contain index files, which means the connection to the directory redirects from the file tree to the index file. Any way to prevent that redirection?
Code for search number from tuple tree? I want to add into my code below. My idea below is to search number from the tree and then print the number. For example, enter input for event is 4, input for strength is 3. Then generate tuple tree. Then user enter number for searching. That number will check every branches in the tuple tree. Then it will printout the number.
Main class code.
package treejava.main;
import java.util.Scanner;
import treejava.utils.TreeUtils;
public class MainClass {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("----Welcome to the Tree Java-Based program-----");
[Code] ....
I am trying to create a tree that is like a take on 21 Questions. The tree pretty much just starts with three default values: the root/first question "Is it a mammal?", a left child "is it: human?", and a right child "is it: fish?", and then it builds off from there. It goes left for YES and right for NO. If the program guesses the wrong animal the user must enter the correct answer and a question that will distinguish the correct answer and the failed answer. That new question then becomes both the the failed answer and new answers's parent.
A little visual:
....................Is it a mammal?
...........It is: human?........Is it: fish?
*lets say it is a mammal but not human, ie a dog
Updated tree:
.....................Is it a mammal?
.....Does it have a tail?............Is it: fish?
Is it: dog?......Is it: human?
My problem is that after I update the tree 3rd time the values do not change properly. Lets say it is a mammal and its does have a tail, BUT its a cat, then, the updated question, which would now go before "is it: dog?" would be something like: "does it chase rodents?", which its left child would be cat and right would be dog.
However, when my program displays the values it would go something like this:
//first run: GOOD
Think of an animal and I will guess it!
Is it a mammal? Enter yes or no:
yes
Is it: human?
no
[Code] .....
So pretty much I can't understand what I'm doing wrong since the values in the print statements are right, but they are wrong during the actual run. Where is my error?
So here is the code that I have. The problem is my insert method. It compiles, but it doesn't do so well in the test class I have set up for it.
package SystemandDesign.BinaryTree;
mport java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
import java.io.ObjectInputStream;
import java.util.Scanner;
[code]....
I know that for a binary search tree the insert() method is easy. You just kept comparing the values of the nodes, and you would know whether to go left or right depending on the value of the node.However, I am stumped when trying to figure out how to add a node into a normal binary tree where you just keep adding the nodes to the leftmost side, regardless of value.Here is my attempt at the insert() method:
public class RegularTree extends BinaryTree {
public CompleteTree() {
super();
}
public void insert(Comparable item) {
if(this.isEmpty()) {
this.setRoot(new TreeNode(item));
return;
[code]....
Is there a way that I can view my entire binary tree on Eclipse? I remember the old IDE that I used, jGrasp, had a feature in its debugging that would allow me to see exactly what was going on and I want to know if Eclipse has the same thing.
View Replies View RelatedHaving trouble adding leaves to my tree. Developing a stand alone Java app using mainly SWT and Eclipse JavaEE on Windows.The tree is like this:
root
------parentA
--------------childA1
--------------childA2
--------------childA3
------parentB
------parentC
--------------childC1
--------------childC2
My requirement: when a child is selected/clicked I want to create a grandchild (there could be from zero to say 12 grandchildren). Thus if user clicks/selects childA2:
root
------parentA
--------------childA1
--------------childA2
----------------------grandchildA21
--------------childA3
------parentB
------parentC
--------------childC1
--------------childC2
Codewise I have:
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
Question one: do I need any further tree related imports to get this to work?
final Tree tree = new Tree(shell, SWT.VIRTUAL | SWT.BORDER | SWT.CHECK | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE );
tree.setHeaderVisible(true);
tree.setBounds(975, 00, 375, 600);
[code]...
And it is here I've tried lots of options but it's like bleak mid winter - no new leaves What seems odd is that I can see the selected/clicked child text item.getText() but if I look at the index it is always -1. And I thought the index would let me create the leaf.
I am new to jsf i have been given a task to create a tree structure in jsf but cant use richfaces and primefaces. I need a complete project for reference as i am to totally new to this.
View Replies View RelatedI have a little problem in my code. Using a threaded binary tree and inorder traversal check if every next element is equal to the previous element + 1. You are allowed to use additional functions as long as they are not recursive. I have implemented everything. Problem is that i cant compare elements as i should. They are type E.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.NoSuchElementException;
import java.util.ArrayList;
[code]....
My task is to implement a B-Tree data structure in Java using no libraries.
My current problem is inserting when the root is full, thus the middle key goes to root.keys[0] and then it get the left and right side which are new Nodes separating and inserting their keys. My problem is that for some reason there is a random second number when in the root and secondly my boolean leaf is always false meaning it never detects that the Tree is deeper than root.
The coding makes sense to me and I have tried printing everywhere but still can't seem to find the problem.
public class BTree {
/*
1. You may not modify the public interface of this class. You may however add any additional methods and/or field which you may require to aid you in the completion of this assignment.
2. You will have to design and implement a Node class. The BTree should house Integer objects.
3. You will notice that there are some overloaded methods, some of which work for Integer objects and some with primitive type int. You have to find a way to implement the methods to work with both types.
*/
class BTreeNode {
boolean leaf = true;
int numKeys = 1;
int mOrder;
Integer keys[];
[Code] ....
I have written a code to get all the nodes below a current Node and it is working but I need to get it to look better if possible. To get the number of nodes below I have created an Array List, which I then go to the first Node below and add all the people to the Array list on the same level till I get to the end of the level, then I go down again until I cannot go down any more. Is there a way I can have my code without having to use an array List? I have put my code below. The brieff about the tree is that you have a parent and below the Parent are children who can have brothers and sisters next to them and after that they also have children below that. The method is trying to find the number of children below any given child
private LinkedList<Node> TempQueue = new LinkedList<Node>();
public int noOfYoungerChildren(Member p1){
Node tmp = find(p1);
return countYoungerChildren(tmp);
[code]....
I create a binary tree and now I would like to display the result in my jsp with conditions.
Each node has 4 elements (id, question, answer, and leftnode rightnode)
If the user clicks "Yes", the program goes to the left of the tree and if he answers "no" to the right of the tree.
For example, the initial question is "you're a man?" If he answers "yes" we will go to the left and page view "you're a singer?" If he answers "no" page displays "you're French? ".
In java, it would
cursor [i]. GetQuestion ()
to the original question.
Then
cursor [i] getQuestion. GetLeftnode ()
For yes and
cursor [i]. GetRightnode (). GetQuestion
for no.
Until the, everything works normally, but when I want to loop until there is no longer any issue by
<c:when test="${not empty cursor[i].getQuestion() }">
The program stops at the first loop and stops it that cursor is not empty
Here is my complete code jstl
<c:set var="cursor" value="${nodes}" scope="session"></c:set>
<c:set var="i" value="0" scope="session"></c:set>
<form>
<c:choose>
<c:when test="${not empty cursor[i].getQuestion() }">
<c:out value="i vaut ${i } au debut de la boucle"></c:out>
[Code] ....