I'm writing the remove method, where you insert the key and it searches the key, if the key is found you remove the value inside the table and return that value, if they key is not found you return null. I did this method but is not returning anything in the main so I try to print inside an if to see if it was entering the condition and it appears to be looping, I'm using arrays because its an assignment
public V remove(K k) {
int key = funcionHash(k);
V key2 = (V) tabla[key].value;
int intento=1;
if(this.estatus[key]==1){
while(intento<this.tabla.length/2){
if(this.tabla[key].key.equals(k)){
My remove(item E) method is working fine if I remove an item that is in the list. However, it has an error when I try to remove an item which is not on the list!
Linked List Class
import java.util.NoSuchElementException;
public class LinkedList<E> { private Node<E> head; // head node of the list private int size = 0; // number of elements that have been added to the list // Returns the element at a specific list index. // Big-O: O(n) (due to the nodeAt call, which must traverse the list) public E get(int index)
So i have used the "remove()" method in conjunction with an iterator to remove an object from a HashSet in my program, and part of my exercise requires me to return said object. What I can do to return an object that has been removed using "remove()" method?
public class School { public final int MIN_GRADE = 0; public final int MAX_GRADE = 100; private int [] grades; public School( int students ) { grades = new int[students];
[Code] ....
The output is :
The numbers in the array are: 1 2 3 4 6 7 8 9 10 13 14 15 The highest grade is: 11
For some reason it is not giving me the highest number in my array. Did I write the method wrong ? Is my array even passing through HighestGrade ?
When out is equal to the String "2x2.5", the array operations ends up looking like this when it is printed using the toString method:
[, , , x]
As you can see, before the array element x, there are three String variables which only contain whitespace. Why does this occur, and how can I prevent this from happening?
Create a method called mirrorImage, which takes two integer arrays as input parameters. You may assume that the two actual parameters have the same length. Your method should return true if the arrays are the reverse of each other. Otherwise mirrorImage should return false.
Examples:
data1:{1,2,3} data2:{3,2,1} ==> true
[code].....
I'm pointing a place outside of the array or something
I am having some problems with some code and I need an extra set of eyes. It appears I've missed something. I am getting a NullPointerException with a Hashtable object, which I can clearly see I've created. So I'm not quite sure why it is happening. I am pretty sure it is do with the code I've posted because I've tested everything else involved.Here is the code where it happens,
I was browsing around and I found a question asking to find how many times a word occurred in a sentence. I am using a hashtable, over kill yes but I need to use them more. However my counter is not working, not really sure why.You can see in the main method I have two repeating names but it returns 0.
package frequency; import java.util.Hashtable; public class CheckFrequency { hashtable<String, Word> words = new Hashtable<String, Word>();
I am having some difficulty adding a new item to the HashTable when a collision occurs. We can only use the basic utilities to code this, so we are coding a HashTable by hand. We have an array of length of 10, which each index holds or will hold a Node for a Linked List.
The code hashes fine, adds the item, but the problem exists when adding items that already been hashed. The project is much bigger, but this is the engine behind the rest, and I figured I would tackle this first.
The items we are adding are objects which are states containing different information, we hash based on the ASCII sum % tableSize.
Here is the code I am testing with to add items:
HashTable ht = new HashTable(10); State az = new State("Arizona","AZ","W",2,"Y",2); State fl = new State("Florida", "FL", "F", 2, "X", 2); State hi = new State("Hawaii", "HI", "H", 3, "Z", 1); State al = new State("Alabama", "AL", "A", 5, "W", 0); ht.insert(hi);
I'm having a problem implementing double hashing when I insert a value into the table i get this for the output:
Insert []. Is there something I'm doing wrong? I'm not getting any errors
public static int size = 0; public static ArrayList<Integer>[] a; public static void interactiveMode(Scanner input) { int menuChoice = 0; do { System.out.println(" Interactive Mode:");
I need to implement a separate-chaining hash table from scratch and I don't need to know the code or anything I would just like an explanation of how I would go about doing the algorithm for this perhaps pseudocode and then I can figure out the rest.
I'm having a problem with double hashing, its supposed to have the user insert an integer into the table and the integer is hashed into the table by the mod of the size of the table so say for instance table size 10 I insert 89 that inserts into 9 because 89%10=9 then i insert 18 that goes into 8 but then once i insert 69 its supposed to collide with index 9 and then uses 7-(69%7) for prime number double hashing...but it just goes into index 9 instead so in 9 it puts 89,69...there's no errors just the wrong output
System.out.print("Enter size of table: "); int n = input.nextInt(); size=n; a = new ArrayList[size]; for (int i = 0; i < size; i++) { a[i] = new ArrayList<Integer>();
How can I write a BufferredImage to an 8-bit .bmp using indexed colors stored in a <String,Color> Hashtable?
I've never used Hashtables before, and I didn't know color indexing existed until now, but I can do most other things in java fairly well.
I'm not looking for code, just the concept, as I really don't know how Hashtables work (although I could figure it out), and how color indexing does. I know how to write image files, just not indexed or with a specific number of bits. I am using Hashtables generated from GIMP.
EDIT: I mainly want to know how to save a BufferedImage as an indexed .bmp.
I mainly would like to know is a int[4][4] or a int [4*4] is more efficient to use. Which takes more storage? Which requires more to process? that kind of stuff.
I have a jsp page that generate a hashtable and display its key-value pairs back to the browser. The problem is that it takes on an average about 15 minutes to build this hashtable, and as a result, I always get a timeout error. What can I do to avoid getting the timeout error without changing the server configuration for timeout
I'm trying to make a calendar that, when you click on the date, the result are stored in a map and visualized in a table that refers to a container.
I successfully created the map mechanism, but I have a problem on the list....
I add the rows in this way:
Object newItemId = container.addItem(); Item riga = container.getItem(newItemId); riga.getItemProperty("Timestamp").setValue(fara); riga.getItemProperty("Date").setValue(asa); . How can I delete a row in the list, when all I have in input is the "Timestamp" information, in a Long value?
I want my jSpinner value "0" to be removed on button click. and I want my jSpinner and jFormattedTextfield and jTextfield value "0" to be Highlighted(e.g: like highlighted by mouse double click) on button click.By removed I mean: nothing to be in the jSpinner. empty as any textfield. the jSpinner default value is 0 and on Click I want the value of the jSpinner to be removed and Highlighted, I need both examples code.
import javax.swing.Timer; import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Ball extends JPanel { private int delay = 10; private Timer timer = new Timer(delay, new TimerListener()); private int x = 0; private int y = 0;
How can I remove the ActionListener from the buttons of my application after i have got something happen.
Please consider the following application:
Java Code:
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Exer1218659 extends JFrame { private String[] textButtons; private Container contents;
[Code] .....
After the line 37 executes I expect that the ActionHandler (ah) will be removed from all of the buttons but this do not happen, then all the remaining button still responding to the clicks. Where is the problem in my code.
My program gives me an error when I try to "digUp" the purse. The error appears in the purse class.
import java.io.*; public class Purse { //Fields public double gp; public double gold; public double silver; public double copper; public double platinum; public static final double GOLD_VALUE = 1;