Question: How to fix this exception? Please help! the small file is a bunch of string like below, it is too much, so i cannot copy

How to fix this exception? Please help!

the small file is a bunch of string like below, it is too much, so i cannot copy all of them.

les Escaldes Andorra la Vella Umm al Qaywayn Ras al-Khaimah Khawr Fakkan Dubai Dibba Al-Hisn Sharjah Ar Ruways Al Fujayrah Al Ain Ajman Adh Dhayd Abu Dhabi Zaranj Taloqan Shindand Shibirghan Shahrak Sar-e Pul Sang-e Charak Aibak Rustaq Qarqin Qarawul Pul-e Khumri Paghman Nahrin Maymana Mehtar Lam Mazar-e Sharif Lashkar Gah Kushk Kunduz Khost Khulm Khash Khanabad Karukh Kandahar Kabul Jalalabad Jabal os Saraj Herat Ghormach Ghazni Gereshk Gardez Fayzabad Farah Kafir Qala Charikar Baraki Barak Bamyan Balkh Baghlan Art Khwajah Asmar Asadabad Andkhoy Bazarak Markaz-e Woluswali-ye Achin 

How to fix this exception? Please help! the small file is a

import java.util.Scanner; import java.util.Vector; import java.util.Arrays; import java.io.File; import java.lang.Math;

public class HashTable{

//The size of the hash table. int TableSize; //The current number of elements in the hash table. int NumElements; //The variable T represents the array used for the table. // DECLARE YOUR TABLE DATA STRUCTURE HERE String[] T; public HashTable(){ NumElements = 0; TableSize = 997; T=new String[TableSize]; // INITIALZE YOUR TABLE DATA STRUCTURE HERE } /* hash(s) = ((3^0)*s[0] + (3^1)*s[1] + (3^2)*s[2] + ... + (3^(k-1))*s[k-1]) mod TableSize (where s is a string, k is the length of s and s[i] is the i^th character of s) Return the hash code for the provided string. The returned value is in the range [0,TableSize-1].

NOTE: do NOT use Java's built in pow function to compute powers of 3. To avoid integer overflows, write a method that iteratively computes powers and uses modular arithmetic at each step. */ public int hash(String s){ int h = 0; for(int i=0; i h += s.charAt(i)*pow(i); } return h%TableSize; } public int pow(int p){ int ans=3; if(p==0){ ans=1; return ans; } if(p==1){ return ans; } for(int i=2;i=0.75){ TableSize=TableSize*2; resize(TableSize); } int i = hash(s); int j = 0; int k = i; while(T[k]!= null){ j++; k=(i+(j*j))%TableSize; } T[k]=s; return k; } /* find(s) Search for the string s in the hash table. If s is found, return the index at which it was found. If s is not found, return -1. */ public int find(String s){ int i = hash(s); int j = 0; int k = i; while (true){ String element = T[k]; if (element == null) return -1; if (s.equals(element)) return k; j++; k=(i+(j*j))%TableSize; } } /* remove(s) Remove the value s from the hash table if it is present. If s was removed, return the index at which it was removed from. If s was not removed, return -1. */ public int remove(String s){ /*NumElements--; if((double)NumElements/TableSize

} /* resize() Resize the hash table to be a prime within the load factor requirements. */ public void resize(int newSize){ while(!isPrime(newSize)){ newSize++; } String[] T2= new String[newSize]; T=T2; } public boolean isPrime(int num){ if(num>2){ for(int i=2;i if(num%i==0){ return false; } return true; } } return false; }

Reading input values from small-txt. Reading table values from small-txt. Read 22107 strings Reading search values from small-txt Read 1865 strings. Reading remove values from small Read strings Exception in thread "main" java lang. ArrayIndexoutof Bounds Exception 387 at HashTable insert HashTable -java 104 at HashTable main HashTable java 257

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 Databases Questions!