Level Order Traversal - 2D Display Of Trees

Apr 6, 2015

We are working with LinkedBinarySearchTrees. One of specs on my assignment is to "Using a level-order traversal, create a 2-D display of your trees, using the forward and back slashes as the branch lines. The tree nodes should be spaced proportionally to show the structure of the tree neatly."

View Replies


ADVERTISEMENT

Binary Tree Post Order / Inorder And Pre-order Traversal

Jan 26, 2014

Any link to the accurate explanation of binary trees in java?

View Replies View Related

Swing/AWT/SWT :: How To Use Container Order Focus Traversal Policy

Feb 1, 2014

the focus traversal policy (hereafter "tab order") in forms and panels doesn't follow the order in which controls were inserted into the container, but is derived from the position of the components on the form or panel. This is very neat (and probably allows sloppy coders and GUI builders to exist without actually ever thinking about the tab order), except when it isn't. As when you actually want to specify a different component order, for example.

In the following example, I've created a form with two columns of buttons. I want the tab order to go through the first column of buttons, followed by second column of buttons (ie. a column-by-column schema). The default tab order is row-by-row, however, and can be obtained for reference by commenting out the setupFocus() call in the constructor.

I had hoped that the ContainerOrderFocusTraversalPolicy would do the job, but there is a couple of problems (which I've addressed in the setupFocus() method). Firstly, the container itself is part of the focus chain. This at least is easily remediable by calling setFocusable(false), but I don't have to do that with the initial focus traversal policy, so I wonder why I have to do it with this one. The other problem is more pressing, though - the ContainerOrderFocusTraversalPolicy lets me (un)hapilly tab through JLabels. Again, I've fixed this, but the initial policy knows all by itself that it's not a good idea to focus a JLabel. Moreover, I'm afraid there might be other components that do not receive focus with the original policy, but ContainerOrderFocusTraversalPolicy might plod though them.

isn't there some focus traversal policy implementation that I could just set and it would tab through exactly the same components as the original policy, except it would order them according to their order in the container?

Code:

package test;
import java.awt.Component;
import java.awt.ContainerOrderFocusTraversalPolicy;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;

[code]...

View Replies View Related

Display If Letters Are In Ascending Order Or Not

Dec 22, 2014

I am trying to make a program that reads a word and display if the letters are in ascending order or not in ascending order(All kind of letters, capitals ). I have made a code but its not 100% correct. My code:

class Main
{
public static void main(String args[]) {
System.out.print( "#Enter text : " );
String text = BIO.getString();
 
[code]...

View Replies View Related

How To Display Number Series In Ascending Order

Aug 9, 2014

tfrreee i want to display given series in ascending order in java prog here is an error : E:Javajdkin>java ascend 505671Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7 at ascend.main(ascend.java:9)

Java Code:

class ascend
{
public static void main (String args[])
{
int s[]={ 50,71,81,21,7};
int i;
for(i=0;i<=s.length;i++)

[Code]...

View Replies View Related

JSP :: Get Double Data Type In Order To Display In The View Through Servlet

Dec 16, 2014

How to get a double data type in order to display in the view through a servlet:

objReferencias.setImprevistos(request.("imprevistos"));

Question:

request.getDouble("imprevistos));? or
request.getDoubleParameter("imprevistos));?

I've been searching but I have not found the appropriate answer.

View Replies View Related

Display Contents Of File In Reverse Order - Output To Console

Jun 24, 2014

Create a class that allows the user to select a file and output the contents of the file to the console. Recommend using a text file to display, java files are text files. You may want to put this code in a method to allow you to complete the remainder of this assignment without overwriting your code.

- You should ask the user to enter the full path to your file to make certain you are processing the correct file.

- Modify your code/add a method to display the contents of the file in reverse order. You do not need to reverse the characters on each line but simply output the lines of the file in reverse order.

Hint: read the content of the file into an ArrayList and then traverse the ArrayList.

this is what i go so far.

package classActivity;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Select
{
public static String enterFilePath()

[Code] ....

View Replies View Related

Calculate Cost Of Ticket Order And Display Receipt For Customer On Screen

Oct 4, 2014

Write a program that will calculate the cost of a ticket order and display the receipt for the customer on the screen. There are 2 ticket prices: adult, and senior citizen. Adult seats are $4.50 and senior citizen seats are $3.50. If more than 5 senior citizen tickets are purchased, the customer gets an extra 20% off the of the ticket order. If more than 10 regular seats are purchased, the customer gets an additional 10% off the cost of the order. A customer can only place an order for one type of ticket. Output the type of ticket purchased, the number of tickets purchased, the gross cost, the amount of the discount, and the final cost of the order.

I am having errors with incaompatible varriables comparing float with doubles.

public class lab3 {
  static Library myLib;
  public static void main (String [] args) {
  Library myLib = new Library(); //Instance the Library class
int ticketNum; //Number of Tickets

[Code] .....

View Replies View Related

Write A Java Application To Display Layout Of Information In Typical Business Card Order

Jun 25, 2014

ABC is a company that designs and prints personal business cards. The company has asked you to write a Java application to display the layout of the information in a typical business card order. Data items in a typical business card include the customer's name, address, city, state, postcode, home phone number, and work phone number.

Write, compile, and test a Java class that displays these data items in a command window. Alternatively, you could also create it using a dialog box. Please include appropriate comments in your class.

Please named your class BusinessCard(LIM).java. (eq. BusinessCardLIM.java)

View Replies View Related

Program That Accept Words And Their Meanings Or Display List Of Words In Lexicographical Order

Apr 15, 2015

Write a menu driven program that either accepts words and their meanings, or displays the list of words in lexicographical order (i.e. as in a dictionary). When an entry is to be added to the dictionary you must first enter the word as one string, and then enter the meaning as separate string. Another requirement - from time to time words become obsolete. When this happens, such word must be removed from the dictionary.

Use the JOptionPane class to enter the information.

Use the concept of linked list to carryout this exercise. You will need at minimum the following classes:

- A WordMeaning class that hold the name of a word and its meaning.
- A WordMeaningNode class that creates the node of information and its link field.
- A WordList class that creates and maintain a linked list of words and their meanings.
- A Dictionary class that test your classes.

For the output, the program should produce two scrollable lists:

- The current list of words and their meanings.
- The list of the deleted words. You need not list the meanings, just the words.

So far, I have everything coded except for the remove method, and I am not sure how to code that. I coded the add method already, but now I don't know where to begin with the remove method in my WordList class. My classes are below.

WordMeaning Class:

public class WordMeaning {
String name;
String definition;
WordMeaning(String t, String d) {
name = t;
definition = d;

[Code] .....

View Replies View Related

Calculate Total Price And Display Total In Order Class

Oct 11, 2014

I'm struggling with inheritance in my assignment. The assignment states that I should use the calculatePrice() to calculate the total price and use another method to display the total. The I must overload the calculatePrice() and add a fee in the SpeedOrder() class.

My main class

package useorder;
import javax.swing.*;
public class UseOrder {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Order.display();

[Code] .....

The problem is mainly displaying the TotalPrice field and. I can't display TotalPrice if it's not static but if it's static I can't inherit it to the SpeedOrder class to assign the total in the overloaded calculateprice method. How can I display the total in my order class and use it in my SpeedOrder class?

View Replies View Related

Breadth First Search Traversal

Dec 5, 2014

This method uses BFS traversal on a vertex and displays the values. I have worked this out on paper and 2 out of 3 the results from my code match my work on paper. I believe the error is that it prints out 3's adjacent child before 3 itself. I have attached the results I did by hand. Here's the graph and results from my code:

0 1 2 3 4 5
------------
0| 0 1 1 0 0 0
1| 0 0 0 0 0 0
2| 0 0 0 1 0 0
3| 1 0 0 0 0 0
4| 0 0 1 0 0 1
5| 0 1 0 1 0 0

BFS:
5 1 3 0 2
4 2 5 0 3 1 //i think this is wrong. shouldnt it be 4 2 5 3 1 0?
0 1 2 3

Here is my code:

public void bfsTraversal(int vertex){
Queue<Integer> q = new LinkedList<Integer>();
visited[vertex] = 1;//mark vertex as visited
q.add(vertex);
System.out.print(vertex + " ");

[Code] .....

Attached image(s)

View Replies View Related

Extract Higher-order Bits Of Random Number In Order To Get Longer Period

Mar 1, 2014

One of the random number generators in Java extract the higher-order bits of the random number in order to get a longer period.

I'm not sure if I understand how this is done. Suppose that the random number r = 0000 1100 1000 1101. If we extract the 16 most significant bits from r; is the new number r = 0000 1100 or r = 0000 1100 0000 0000?

View Replies View Related

Display If Letters Are In Ascending Order Or Not In Ascending

Dec 22, 2014

I am trying to make a programm that reads a word and display if the letters are in ascending order or not in ascending order(All kind of letters..capitals..etc). I have made a code but its not 100% correct.

My code:

class Main
{
public static void main(String args[])
{
System.out.print( "#Enter text : " );
String text = BIO.getString();
while ( ! text.equals( "END" ) )
{
if (text.equals("END"))

[Code] ....

View Replies View Related

Method To Do Inorder Traversal For Class

May 4, 2014

I need a method to do an inorder traversal for the following class

public class TreeNode {
/** the data stored at this node */
private String data;
/** the left child */
private TreeNode left;
 
[Code] ....

View Replies View Related

Swing/AWT/SWT :: How To Customize Focus Traversal Through Tab Key

Apr 29, 2014

I'm facing a problem in controlling the focus traversal mechanism inside a jframe...as i want the focus to travel from top to bottom by pressing tab key regularly , but it travels left to right and then top to bottom through the textfields... The form looks like
textfield1 textfield4

textfield2 textfield5

textfield3

The focus travels from 1 to 4 , 2 to 5 and then rests at 3. but i want it to be like from 1 to 2 to 3 and then 4 and 5....

View Replies View Related

How To Write Inorder-method For Trees

Mar 29, 2015

I have a question related to trees in Java. The following code is given:

public class BinarySearchTree {
private Node root;
public BinarySearchTree() {
this.root = null;
}
public BinarySearchTree(Node root) {

[Code] ....

The inorder-method is the one that really imports. I have to go through a tree using the Inorder-method. I do understand how this works, however I don't understand how the code fits to the inorder process. I understand the code up to the point where it reaches the most left "root", but then I do not know how to go further. How do I reach the root above then?

View Replies View Related

Constructing Expression Trees In Java By Using BST

May 5, 2014

In this i Write a Java program to parse a syntactically correct arithmetical expression and produce an equivalent Expression TREE. Remember, in an expression tree the terminal nodes are variables and constants, and the interior nodes are operators (such as +,-,*,/). For instance the expression: (1 + 2) * 3 can be represented by the following tree:

INPUT Expression
(1 +2)*3
POSTORDER Expression
1 2 + 3 *
TREE [root=asd.reg.Node@56ddc58]

But when I Execute the program it Shows only Prefix and postfix .But the requered output is in inorder preorder and postorder ...

import ava.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
import javax.swing.tree.TreeNode;

[code]....

View Replies View Related

Create A Dictionary In Java Using Search Trees

Jul 28, 2014

I have to create a dictionary in java using search trees. I have problems with the methods put() and remove(). Working properly, ie correctly adds a new element and eliminates correctly. But I should improve a few things.

As you can see from the interface, both methods must return an element of type V, that is:

- case put(): returns the previous value associated with key (or null if the key was not associated with any value)
- case remove(): returns the value associated with the key (or null if the key was not present in the dictionary)

I do not understand how come my put method always returns null even though in reality I make him return node.getElement().

Instead, the remove() method does not know how to modify it to make sure it returns the value associated with the key. If I change the helper method return value in V (instead of Node<K, V>) method does not work anymore...

How can I then edit these two methods?

Class SearchTree:
public class SearchTree<K extends Comparable, V> implements Dictionary<K, V> {
public int size;
public Node<K, V> root;
public SearchTree() {
root = null;
size = 0;

[Code] ....

View Replies View Related

Unable To Clear All Graphical Objects Of A Type Trees

Oct 20, 2014

I am trying to clear all graphical objects of a certain type(all trees in particular). I have never had any issues doing so, and this method normally works well along with these variables:

Java Code:

public static ArrayList<GRect> historyT;
public static ArrayList<GOval> historyL;
public static GRect trunk;
public static GOval leave;
public void deleteTrees() {
//clears all tree trunks and leaves

[Code]...

That is this normally worked until I started added more trees to the screen after they had all been erased. What happens is that it won't clear all of them unless the max has been reached, that is 6. It will remove all trees up till the last one if the max has not been reached. In other words here is my screen before the clear all if the max has not been reached(* is a tree, _ is erased): ****

Here is it after: _ _ _ _ *

So my question is, is why aren't all the trees deleted? Why does it leave one left behind?

View Replies View Related

Binary Search Trees Theory - Sequence Of Keys?

Mar 15, 2014

Suppose that a certain BST has keys that are integers between 1 and 10, and we search for 5. Which sequence below cannot be the sequence of keys examined?

(a) 10,9,8,7,6,5
(b) 4,10, 8, 6, 5
(c)1,10,2,9,3,8,4,7,6,5
(d) 2,7,3,8,4,5
(e)1,2,10,4,8,5

I've noticed many differences, such as there is only one with an odd number of keys, and one has all integers from 1-10 inside of it, but I can't find any real reason that you wouldn't be able to search it?

View Replies View Related

Constructing Expression Trees In Java By Using Binary Search Tree

May 6, 2014

I Write a Java program to parse a syntactically correct arithmetical expression and produce an equivalent Expression TREE. Remember, in an expression tree the terminal nodes are variables and constants, and the interior nodes are operators (such as +,-,*,/).

For instance the expression: (1 + 2) * 3 can be represented by the following tree:

INPUT Expression
(1 +2)*3
POSTORDER Expression
1 2 + 3 *
TREE [root=asd.reg.Node@56ddc58]

But when i Execute the program it Shows only Prefix and postfix .But the requered output is in inorder preorder and postorder so how to solve these error

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
import javax.swing.tree.TreeNode;
public class InToPost {
private static String str;

[Code] .....

View Replies View Related

Creating A Level Editor GUI

Nov 17, 2014

I am working on a game engine with java. I have come to the final stages of the development of this engine now and need a small hand. For this i am using java's built in libary for graphics. and am strugling to create a nice looking GUi with it, What i need:

The class extends the canvas class and adds it to the jframe, i have set the window up as standard and added a menubar, and net the canvas, what I want to do.

For those of you that have used application such as tiled (shown here [URL] .....) what i am wanting to do is create a gui around the canvas similar to this where the parts on the right are resizable up and down and in and out. i was wondering how i would go about incorporating this.

View Replies View Related

Can't Override A Method - It Still Ask For Level 1.5 Or Greater

Apr 29, 2014

I'm using "standard-kepler-SR2-win32-x86_64" and have installed "jdk-8u5-windows-x64".

But eventhough I can't override a methode like that "@override", it still says me:"annotations are only available, if source lever is 1.5 or greater".

Fine, therefore I installad "jdk-8u5-windows-x64", its the higest one on that oracle side, what else is needed?

View Replies View Related

JSF :: How To Handle Lower Level Exception

Jan 7, 2015

I have come across some code where it attempts to save an entity to a database, but before it does it validates that the name of the entity is unique. If it is not unique it throws a runtime exception. This results in the ugly default exception web page being displayed. Is there any way to propagate this back to the JSF page where the user enters and clicks the form button to save the entity? The page already handles some error cases such as "field required" using the h:inputText's 'required' attribute. Need something more for name validation.

View Replies View Related

Initialization Of Variables At Class Level

Feb 11, 2014

if I declare

class Example
{
int x=10;
......
}

It is not showing any error but when I declare

class Example
{
int x;
x=10;
............
}

it showing compile time error ....

View Replies View Related







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