How To Program Family Tree

May 7, 2015

I have to write a program that will input and display a person's family tree. I'm using BlueJ.

View Replies


ADVERTISEMENT

Program That Takes In Family Members Calculate Family Average Age And Prints Out AI

Mar 9, 2014

I 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 Related

Family Tree - Cannot Enter Anything When Text Box Pops Up And Ask To Start With Root Name

Apr 13, 2014

The 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] ....

View Replies View Related

Java Tree Structure - Build Tree Based On Traversal Results

Jun 17, 2014

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?

View Replies View Related

234 Tree Search And Insert

Apr 15, 2014

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] ....

View Replies View Related

Binary Expression Tree

Apr 23, 2015

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]....

View Replies View Related

Creating A Tree In Java

Sep 9, 2014

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.

View Replies View Related

Tree Structure Of Folders

Mar 21, 2014

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] ....

View Replies View Related

Java N-node Tree

Mar 30, 2015

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.

View Replies View Related

Displaying All Paths In A Tree

Nov 20, 2014

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.

View Replies View Related

Recursive Method For A Tree

May 9, 2015

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]....

View Replies View Related

Binary Tree Depth

Apr 2, 2014

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]....

View Replies View Related

Java B-Tree Insert (no Libraries)

Apr 11, 2014

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] ....

View Replies View Related

How To Store Parse Tree In Database

Jan 23, 2014

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 Related

Viewing Website File Tree

Apr 25, 2014

This 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?

View Replies View Related

How To Search Number From Tuple Tree

May 21, 2015

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] ....

View Replies View Related

Tree Not Updating Values Properly

Aug 20, 2014

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?

View Replies View Related

Binary Tree Insert Method

Mar 24, 2014

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]....

View Replies View Related

Inserting Into A Regular Binary Tree?

Nov 26, 2014

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]....

View Replies View Related

How To View Binary Tree Using Eclipse

Aug 7, 2014

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 Related

Swing/AWT/SWT :: Creating New Leaves In Tree

Aug 26, 2014

Having 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.

View Replies View Related

JSF :: Tree Structure - Cannot Use Richfaces And Primefaces

Apr 9, 2014

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 Related

Binary Threaded Tree Comparing

Dec 4, 2014

I 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]....

View Replies View Related

Java B-Tree Insert (no Libraries)

Apr 11, 2014

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] ....

View Replies View Related

Java Binary Tree Code

Apr 5, 2014

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]....

View Replies View Related

JSP :: Binary Tree - Loops In JSTL

Jan 31, 2014

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] ....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved