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."
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?
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();
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++)
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()
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
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)
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;
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?
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:
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?
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"))
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....
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?
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:
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;
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?
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?
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?
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:
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;
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.
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.