Question
This is a hashing assignment I need help with. The moto is to get the output : $ javac Main.java && java Main Testing insert
This is a hashing assignment I need help with. The moto is to get the output :
$ javac Main.java && java Main Testing insert method: Inserting keys: 'cat','food','taste','great', Resulting Dictionary: |food|___|___|___|___|great|cat|taste| Testing search method: 'x' not found 'cat' found in bucket 6 'food' found in bucket 0 'hotdog' not found 'taste' found in bucket 7 'great' found in bucket 5 'y' not found Testing delete method: 'cat' has been deleted 'hotdog' can't be deleted 'good' can't be deleted 'great' has been deleted 'cat' can't be deleted Resulting Dictionary: |food|___|___|___|___|-DELETED-|-DELETED-|taste| Testing search method: 'x' not found 'cat' not found 'food' found in bucket 0 'hotdog' not found 'taste' found in bucket 7 'great' not found 'y' not found
***********************************************************************************************************
Here's my program:
public class Dictionary { private int maxSize; private String[] hash; public Dictionary() { maxSize = 8; hash = new String[maxSize]; for(int i = 0; i ******************************************************************************************************** import java.util.*; public class tester { public static void main(String[] args) { Dictionary dic = new Dictionary(); dic.insert("cat"); dic.insert("food"); dic.insert("taste"); dic.insert("great"); System.out.println("Testing search method:"); int search = dic.search("x"); if(search == -1) System.out.println("'x' not found"); else System.out.println("'x' found in bucket "+ search); search = dic.search("cat"); if(search == -1) System.out.println("'cat' not found"); else System.out.println("'cat' found in bucket "+ search); search = dic.search("food"); if(search==-1) System.out.println("'food' not found"); else System.out.println("'food' found in bucket "+ search); search = dic.search("hotdog"); if(search==-1) System.out.println("'hotdog' not found"); else System.out.println("'hotdog' found in bucket "+ search); search = dic.search("taste"); if(search==-1) System.out.println("'taste' not found"); else System.out.println("'taste' found in bucket "+ search); search = dic.search("great"); if(search==-1) System.out.println("'great' not found"); else System.out.println("'great' found in bucket "+ search); search = dic.search("y"); if(search==-1) System.out.println("'y' not found"); else System.out.println("'y' found in bucket "+ search); System.out.println(" Testing delete method"); boolean del; del = dic.delete("cat"); if(del) System.out.println("'cat' has been deleted"); else System.out.println("'cat' cant be deleted "+ del); del = dic.delete("hotdog"); if(del) System.out.println("'hotdog' has been deleted"); else System.out.println("'hotdog' cant be deleted "+ del); del = dic.delete("good"); if(del) System.out.println("'good' has been deleted"); else System.out.println("'good' cant be deleted "+ del); del = dic.delete("great"); if(del) System.out.println("'great' has been deleted"); else System.out.println("'great' cant be deleted "+ del); del = dic.delete("cat"); if(del) System.out.println("'cat' has been deleted"); else System.out.println("'cat' cant be deleted "+ del); System.out.println("Resulting Dictionary: "+(dic.toString())); System.out.println("Testing search method:"); search = dic.search("x"); if(search == -1) System.out.println("'x' not found"); else System.out.println("'x' found in bucket "+ search); search = dic.search("cat"); if(search == -1) System.out.println("'cat' not found"); else System.out.println("'cat' found in bucket "+ search); search = dic.search("food"); if(search==-1) System.out.println("'food' not found"); else System.out.println("'food' found in bucket "+ search); search = dic.search("hotdog"); if(search==-1) System.out.println("'hotdog' not found"); else System.out.println("'hotdog' found in bucket "+ search); search = dic.search("taste"); if(search==-1) System.out.println("'taste' not found"); else System.out.println("'taste' found in bucket "+ search); search = dic.search("great"); if(search==-1) System.out.println("'great' not found"); else System.out.println("'great' found in bucket "+ search); search = dic.search("y"); if(search==-1) System.out.println("'y' not found"); else System.out.println("'y' found in bucket "+ search); } } ***************************************************** The output I get is : Food and taste are not matching also need the insert method.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started