Question: urgent in java, pls provide output as well on TODOs HASHTABLE.JAVA public class HashTable { NGen[] hashtable; int size; // HashTable constructor public HashTable() {

urgent in java, pls provide output as well on TODOs

HASHTABLE.JAVA

public class HashTable { NGen[] hashtable; int size; // HashTable constructor public HashTable() { hashtable = new NGen[100]; size = 100; } // TODO: Implement the add method. public void add(T item) { // To begin, you should call hash (or betterHash) on your item. // This will be the index of the item in your hashtable // Next, use an NGen variable to represent a node within the hashtable // The rest is up to you, but BE SURE TO USE CHAINING TO DEAL WITH COLLISIONS // For just milestone 1, you will want to change the signature of this method // to add(T item, int index) so that you can hard code indexes for testing // before having written hash/betterHash. } // TODO: Implement a hash function for your hash table public int hash(T key) { // convert input to a string // set a hash value // loop over the string to hash each character // you may need to convert individual characters to integers // one way to d0 this is through something like: (int) s.charAt(i) return 0; } // TODO: Implement a better hash function // In this lab, we will define a "better" hash function as one with fewer collisions public int betterHash(T key) { return 0; } // Displays the hash table and associated statistics. DO NOT MODIFY. public void display() { int collisions = 0; for (int i = 0; i < hashtable.length; i++) { if (hashtable[i] != null) { int hit = 0; NGen temp = hashtable[i]; System.out.print(i + ":\t "); while(temp != null) { System.out.print(temp.getData() + " "); temp = temp.getNext(); hit++; if (hit > 1) collisions++; } System.out.println(); } else { System.out.println(i + ":"); } } System.out.println("Collisions: " + collisions); } public static void main(String args[]) { HashTable h = new HashTable(); // TODO: write some test cases for milestone 1 to show your functional add method // TODO: comment in the following section for milestones 2 and 3 after writing a functional add method // Do not modify! /* // From TextScan.java Scanner readFile = null; String filename = "gettysburg.txt"; String s; try { readFile = new Scanner(new File(filename)); } catch (FileNotFoundException e) { System.out.println("File: " + filename + " not found"); System.exit(1); } while (readFile.hasNext()) { s = readFile.next(); h.add(s); } h.display(); */ } } // END HASHTABLE.JAVA

NGEN.JAVA

public class NGen { // constructors public NGen () {} public NGen (T o, NGen link) { data = o; next = link; } // selectors public T getData() { return data; } public void setData(T o) { data = o; } public NGen getNext() { return next; } public void setNext(NGen link) { next = link; } // instance variables private T data; private NGen next; } // END NGEN.JAVA

.TXT FILE

Abraham Lincoln's Gettysburg Address

Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.

Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battlefield of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should d0 this.

But, in a larger sense, we cannot dedicatewe cannot consecratewe cannot hallowthis ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before usthat from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotionthat we here highly resolve that these dead shall not have died in vainthat this nation, under God, shall have a new birth of freedom and that government of the people, by the people, for the people, shall not perish from the earth.

// END .TXT file

will give a thumbs up w output provided

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!