SlideShare a Scribd company logo
1 of 12
Download to read offline
Given the code below create a method called, getCollisionCount that will return the number of
collisions that occurred. This method will be inside the hasedDictionary class. Please do not use
setNext getNext methods or any nodes just use what's provided in the code below
import java.util.Iterator;
public interface DictionaryInterface
{
/** Adds a new entry to this dictionary. If the given search key already
exists in the dictionary, replaces the corresponding value.
@param key An object search key of the new entry.
@param value An object associated with the search key.
@return Either null if the new entry was added to the dictionary
or the value that was associated with key if that value
was replaced. */
public V add(K key, V value);
/** Removes a specific entry from this dictionary.
@param key An object search key of the entry to be removed.
@return Either the value that was associated with the search key
or null if no such object exists. */
public V remove(K key);
/** Retrieves from this dictionary the value associated with a given
search key.
@param key An object search key of the entry to be retrieved.
@return Either the value that is associated with the search key
or null if no such object exists. */
public V getValue(K key);
/** Sees whether a specific entry is in this dictionary.
@param key An object search key of the desired entry.
@return True if key is associated with an entry in the dictionary. */
public boolean contains(K key);
/** Creates an iterator that traverses all search keys in this dictionary.
@return An iterator that provides sequential access to the search
keys in the dictionary. */
public Iterator getKeyIterator();
/** Creates an iterator that traverses all values in this dictionary.
@return An iterator that provides sequential access to the values
in this dictionary. */
public Iterator getValueIterator();
/** Sees whether this dictionary is empty.
@return True if the dictionary is empty. */
public boolean isEmpty();
/** Gets the size of this dictionary.
@return The number of entries (key-value pairs) currently
in the dictionary. */
public int getSize();
/** Removes all entries from this dictionary. */
public void clear();
} // end DictionaryInterface
//hasheddictionay class
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* A class that implements the ADT dictionary by using hashing and
* linear probing to resolve collisions.
* The dictionary is unsorted and has distinct search key.
Search keys and associated values are not null.
*/
public class HashedDictionary implements DictionaryInterface
{
// The dictionary:
private int numberOfEntries;
private static final int DEFAULT_CAPACITY = 5; // Must be prime
private static final int MAX_CAPACITY = 10000;
// The hash table:
private Entry[] hashTable;
private int tableSize; // Must be prime
private static final int MAX_SIZE = 2 * MAX_CAPACITY;
private boolean integrityOK = false;
private static final double MAX_LOAD_FACTOR = 0.5; // Fraction of
// hash table that can be filled
protected final Entry AVAILABLE = new Entry<>(null, null);
public HashedDictionary()
{
this(DEFAULT_CAPACITY); // Call next constructor
} // end default constructor
public HashedDictionary(int initialCapacity)
{
initialCapacity = checkCapacity(initialCapacity);
numberOfEntries = 0; // Dictionary is empty
// Set up hash table:
// Initial size of hash table is same as initialCapacity if it is prime;
// otherwise increase it until it is prime size
tableSize = getNextPrime(initialCapacity);
checkSize(tableSize); // Check that size is not too large
// The cast is safe because the new array contains null entries
@SuppressWarnings("unchecked")
Entry[] temp = (Entry[])new Entry[tableSize];
hashTable = temp;
integrityOK = true;
} // end constructor
/* Implementations of methods in DictionaryInterface are here. . . .*/
public boolean isEmpty()
{
return this.numberOfEntries == 0;
}//end isEmpty
public Iterator getValueIterator()
{
throw new NoSuchElementException("Value Iterator Not Implemented");
}//end valueIterator
public void clear()
{
checkIntegrity();
for (int index = 0; index < this.hashTable.length; index++)
{
hashTable[index] = null;
}//end of for
this.numberOfEntries = 0;
}//end clear
public Iterator getKeyIterator()
{
return new KeyIterator();
}//end iterator
public boolean contains(K key)
{
return getValue(key) != null;
}//end contains
public int getSize()
{
return this.numberOfEntries;
}//end getSize
public V remove(K key) {
checkIntegrity();
int index = getHashIndex(key);
while (hashTable[index] != null) {
if (hashTable[index].getKey().equals(key)) {
V value = hashTable[index].getValue();
hashTable[index].setValue(null);
hashTable[index] = AVAILABLE;
numberOfEntries--;
return value;
}
index = (index + 1) % hashTable.length;
}
// If the key is not found, return null
return null;
}
public V getValue(K key)
{
checkIntegrity();
V result = null;
int index = getHashIndex(key);
if ((hashTable[index] != null) && (hashTable[index] != AVAILABLE))
result = hashTable[index].getValue(); // Key found; get value
// Else key not found; return null
return result;
} // end getValue
public V add(K key, V value)
{
int index;
V oldValue;
if((key == null) || (value == null))
{
throw new NoSuchElementException();
}
index = getHashIndex(key);
if((hashTable[index] != null) && (hashTable[index] != AVAILABLE))
{
hashTable[index] = new Entry(key,value);
numberOfEntries++;
oldValue = null;
}
else
{
oldValue = hashTable[index].getValue();
hashTable[index].setValue(value);
}
if(isHashTableTooFull())
{
enlargeHashTable();
}
return oldValue;
}//end of add
/* END of Implementations of dictionary methods are here^. . . . */
/* Implementations of private methods are here. . . . */
//precondition: checkIntegrity has been called
private void enlargeHashTable()
{
Entry[] oldTable = hashTable;
int oldSize = hashTable.length;
int newSize = getNextPrime(oldSize + oldSize);
checkSize(newSize);
//The cast is safe because the new array contains null entries
@SuppressWarnings("unchecked")
Entry[] temp = (Entry[]) new Entry[newSize];
hashTable = temp;
numberOfEntries = 0;//reset number of dictionary entries, since it will be incremented by add
during rehash
//rehash dictionary entries from old array to the new and bigger array;
//skip elements that contain null or available
for(int index = 0; index < oldSize; index++)
{
if((oldTable[index] != null) && (oldTable[index] != AVAILABLE))
{
add(oldTable[index].getKey(), oldTable[index].getValue());
}
}// end for
}//end enlargeHashTable
private int getHashIndex(K key)
{
int hashIndex = key.hashCode() % hashTable.length;
if(hashIndex < 0)
{
hashIndex = hashIndex + hashTable.length;
}
return hashIndex;
}//end getHashIndex
private void checkIntegrity()
{
if(!integrityOK)
{
throw new SecurityException("objecy is currupt");
}
}//end checkIntegrity
private boolean isHashTableTooFull()
{
if((numberOfEntries / hashTable.length) >= MAX_LOAD_FACTOR)
{
return true;
}
else
{
return false;
}
}//end isHashTableTooFull
private int checkSize(int size)
{
if(size >= MAX_SIZE){throw new IllegalStateException("Dictionary has become too large.");}
else{return size;}
}//end checksize
private int checkCapacity(int cap)
{
if(cap < DEFAULT_CAPACITY)
{
cap = DEFAULT_CAPACITY;
}
else if (cap > MAX_CAPACITY)
{
throw new IllegalStateException("Attempt to create a dictionary " + "whose capacity is larger
than " + MAX_CAPACITY);
}
return cap;
}//end checkcap
private int getNextPrime(int integer)
{
// if even, add 1 to make od
if (integer % 2 == 0)
{
integer++;
} // end if
// test odd integers
while (!isPrime(integer))
{
integer = integer + 2;
} // end while
return integer;
}//end getnextprime
private boolean isPrime(int integer)
{
boolean result;
boolean done = false;
// 1 and even numbers are not prime
if ( (integer == 1) || (integer % 2 == 0) )
{
result = false;
}
// 2 and 3 are prime
else if ( (integer == 2) || (integer == 3) )
{
result = true;
}
else // integer is odd and >= 5
{
assert (integer % 2 != 0) && (integer >= 5);
// a prime is odd and not divisible by every odd integer up to its square root
result = true; // assume prime
for (int divisor = 3; !done && (divisor * divisor <= integer); divisor = divisor + 2)
{
if (integer % divisor == 0)
{
result = false; // divisible; not prime
done = true;
} // end if
} // end for
} // end if
return result;
} // end isPrime
/* END of Implementations of private methods are here^. . . . */
protected final class Entry
{
private K key;
private V value;
private Entry(K searchKey, V dataValue)
{
key = searchKey;
value = dataValue;
}//end contructor
private K getKey()
{
return key;
}//end getKey
private V getValue()
{
return value;
}//end value
private void setValue(V newValue)
{
value = newValue;
}//end setValue
} // end Entry
private class KeyIterator implements Iterator
{
private int currentIndex; // Current position in hash table
private int numberLeft; // Number of entries left in iteration
private KeyIterator()
{
currentIndex = 0;
numberLeft = numberOfEntries;
} // end default constructor
public boolean hasNext()
{
return numberLeft > 0;
} // end hasNext
public void remove()
{
throw new UnsupportedOperationException();
} // end remove
public K next()
{
K result = null;
if (hasNext())
{
// Skip table locations that do not contain a current entry
while ( (hashTable[currentIndex] == null) ||
(hashTable[currentIndex] == AVAILABLE) )
{
currentIndex++;
} // end while
result = hashTable[currentIndex].getKey();
numberLeft--;
currentIndex++;
}
else
throw new NoSuchElementException();
return result;
} // end next
} // end KeyIterator
} // end HashedDictionary

More Related Content

Similar to Given the code below create a method called, getCollisionCount that .pdf

So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfaksahnan
ย 
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackageย ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackageย ed.docxweek4_srcArrayMethods.javaweek4_srcArrayMethods.javapackageย ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackageย ed.docxalanfhall8953
ย 
You are to write an efficient program that will read a dictionary of.pdf
You are to write an efficient program that will read a dictionary of.pdfYou are to write an efficient program that will read a dictionary of.pdf
You are to write an efficient program that will read a dictionary of.pdffortmdu
ย 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfseoagam1
ย 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfmail931892
ย 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfmail931892
ย 
Answer this question for quality assurance. Include a final applicat.pdf
Answer this question for quality assurance. Include a final applicat.pdfAnswer this question for quality assurance. Include a final applicat.pdf
Answer this question for quality assurance. Include a final applicat.pdfakanshanawal
ย 
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docxMETA-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docxandreecapon
ย 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docxajoy21
ย 
Program 4You are to write an efficient program that will read a di.pdf
Program 4You are to write an efficient program that will read a di.pdfProgram 4You are to write an efficient program that will read a di.pdf
Program 4You are to write an efficient program that will read a di.pdfezzi552
ย 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxcurwenmichaela
ย 
Here is what I got so far, I dont know how to write union, interse.pdf
Here is what I got so far, I dont know how to write union, interse.pdfHere is what I got so far, I dont know how to write union, interse.pdf
Here is what I got so far, I dont know how to write union, interse.pdfarihantpatna
ย 
4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdf4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdfmumnesh
ย 
I need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdfI need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdffonecomp
ย 
This project will implement a simple usernamepassword lookup system.pdf
This project will implement a simple usernamepassword lookup system.pdfThis project will implement a simple usernamepassword lookup system.pdf
This project will implement a simple usernamepassword lookup system.pdfezhilvizhiyan
ย 
Given the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdfGiven the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdfNicholasflqStewartl
ย 
Describe a data structure to represent sets of elements (each element.pdf
Describe a data structure to represent sets of elements (each element.pdfDescribe a data structure to represent sets of elements (each element.pdf
Describe a data structure to represent sets of elements (each element.pdfrajeshjain2109
ย 
Please add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxPlease add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxStewartt0kJohnstonh
ย 
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdfLabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdffantasiatheoutofthef
ย 

Similar to Given the code below create a method called, getCollisionCount that .pdf (20)

So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdf
ย 
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackageย ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackageย ed.docxweek4_srcArrayMethods.javaweek4_srcArrayMethods.javapackageย ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackageย ed.docx
ย 
You are to write an efficient program that will read a dictionary of.pdf
You are to write an efficient program that will read a dictionary of.pdfYou are to write an efficient program that will read a dictionary of.pdf
You are to write an efficient program that will read a dictionary of.pdf
ย 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdf
ย 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
ย 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
ย 
Answer this question for quality assurance. Include a final applicat.pdf
Answer this question for quality assurance. Include a final applicat.pdfAnswer this question for quality assurance. Include a final applicat.pdf
Answer this question for quality assurance. Include a final applicat.pdf
ย 
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docxMETA-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
ย 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docx
ย 
Program 4You are to write an efficient program that will read a di.pdf
Program 4You are to write an efficient program that will read a di.pdfProgram 4You are to write an efficient program that will read a di.pdf
Program 4You are to write an efficient program that will read a di.pdf
ย 
AutoComplete
AutoCompleteAutoComplete
AutoComplete
ย 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
ย 
Here is what I got so far, I dont know how to write union, interse.pdf
Here is what I got so far, I dont know how to write union, interse.pdfHere is what I got so far, I dont know how to write union, interse.pdf
Here is what I got so far, I dont know how to write union, interse.pdf
ย 
4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdf4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdf
ย 
I need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdfI need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdf
ย 
This project will implement a simple usernamepassword lookup system.pdf
This project will implement a simple usernamepassword lookup system.pdfThis project will implement a simple usernamepassword lookup system.pdf
This project will implement a simple usernamepassword lookup system.pdf
ย 
Given the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdfGiven the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdf
ย 
Describe a data structure to represent sets of elements (each element.pdf
Describe a data structure to represent sets of elements (each element.pdfDescribe a data structure to represent sets of elements (each element.pdf
Describe a data structure to represent sets of elements (each element.pdf
ย 
Please add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxPlease add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docx
ย 
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdfLabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
ย 

More from aucmistry

Consider the Project article 2 titled Readiness for Organizational .pdf
 Consider the Project article 2 titled Readiness for Organizational .pdf Consider the Project article 2 titled Readiness for Organizational .pdf
Consider the Project article 2 titled Readiness for Organizational .pdfaucmistry
ย 
Consider the pedigree for Waardenburg syndrome which is an autosomal .pdf
 Consider the pedigree for Waardenburg syndrome which is an autosomal .pdf Consider the pedigree for Waardenburg syndrome which is an autosomal .pdf
Consider the pedigree for Waardenburg syndrome which is an autosomal .pdfaucmistry
ย 
Consider the imaginary nation of Leguminia, whose citizens only consu.pdf
 Consider the imaginary nation of Leguminia, whose citizens only consu.pdf Consider the imaginary nation of Leguminia, whose citizens only consu.pdf
Consider the imaginary nation of Leguminia, whose citizens only consu.pdfaucmistry
ย 
Consider the investment projects in the table below, all of which hav.pdf
 Consider the investment projects in the table below, all of which hav.pdf Consider the investment projects in the table below, all of which hav.pdf
Consider the investment projects in the table below, all of which hav.pdfaucmistry
ย 
Consider the following method. Answer the following 1. Describe the w.pdf
 Consider the following method. Answer the following 1. Describe the w.pdf Consider the following method. Answer the following 1. Describe the w.pdf
Consider the following method. Answer the following 1. Describe the w.pdfaucmistry
ย 
Consider the following statistics From 2010 to 2011 GDP grew by 2.3.pdf
 Consider the following statistics From 2010 to 2011 GDP grew by 2.3.pdf Consider the following statistics From 2010 to 2011 GDP grew by 2.3.pdf
Consider the following statistics From 2010 to 2011 GDP grew by 2.3.pdfaucmistry
ย 
Consider the following table I am trying to do a substring on SELECT.pdf
 Consider the following table I am trying to do a substring on SELECT.pdf Consider the following table I am trying to do a substring on SELECT.pdf
Consider the following table I am trying to do a substring on SELECT.pdfaucmistry
ย 
Consider the following closed economy, C=480+0.8(YT),Pp=100,G=20, w.pdf
 Consider the following closed economy, C=480+0.8(YT),Pp=100,G=20, w.pdf Consider the following closed economy, C=480+0.8(YT),Pp=100,G=20, w.pdf
Consider the following closed economy, C=480+0.8(YT),Pp=100,G=20, w.pdfaucmistry
ย 
Consider the data for the mean number of days with precipitation more.pdf
 Consider the data for the mean number of days with precipitation more.pdf Consider the data for the mean number of days with precipitation more.pdf
Consider the data for the mean number of days with precipitation more.pdfaucmistry
ย 
Consider the following documents Doc 1 pat sat on mat Doc 2 cat sa.pdf
 Consider the following documents Doc 1 pat sat on mat Doc 2 cat sa.pdf Consider the following documents Doc 1 pat sat on mat Doc 2 cat sa.pdf
Consider the following documents Doc 1 pat sat on mat Doc 2 cat sa.pdfaucmistry
ย 
Consider the continuous random variable, Y, with moment generating fu.pdf
 Consider the continuous random variable, Y, with moment generating fu.pdf Consider the continuous random variable, Y, with moment generating fu.pdf
Consider the continuous random variable, Y, with moment generating fu.pdfaucmistry
ย 
Consider the case in which query involves a single variable. Let X be.pdf
 Consider the case in which query involves a single variable. Let X be.pdf Consider the case in which query involves a single variable. Let X be.pdf
Consider the case in which query involves a single variable. Let X be.pdfaucmistry
ย 
Haz un resumen del siguiente pasaje y dale un t๏ฟฝtulo adecuado. Has.pdf
Haz un resumen del siguiente pasaje y dale un t๏ฟฝtulo adecuado. Has.pdfHaz un resumen del siguiente pasaje y dale un t๏ฟฝtulo adecuado. Has.pdf
Haz un resumen del siguiente pasaje y dale un t๏ฟฝtulo adecuado. Has.pdfaucmistry
ย 
Hay nueve filos principales descritos -Referencias - Mollusca, P.pdf
Hay nueve filos principales descritos -Referencias - Mollusca, P.pdfHay nueve filos principales descritos -Referencias - Mollusca, P.pdf
Hay nueve filos principales descritos -Referencias - Mollusca, P.pdfaucmistry
ย 
Have you ever driven through a rural area and thought, There is not.pdf
Have you ever driven through a rural area and thought, There is not.pdfHave you ever driven through a rural area and thought, There is not.pdf
Have you ever driven through a rural area and thought, There is not.pdfaucmistry
ย 
Harvey Inc. has a Current E&P balance of ($100,000) earned ratably t.pdf
Harvey Inc. has a Current E&P balance of ($100,000) earned ratably t.pdfHarvey Inc. has a Current E&P balance of ($100,000) earned ratably t.pdf
Harvey Inc. has a Current E&P balance of ($100,000) earned ratably t.pdfaucmistry
ย 
Harris Corporation provides the following data on a proposed capital.pdf
Harris Corporation provides the following data on a proposed capital.pdfHarris Corporation provides the following data on a proposed capital.pdf
Harris Corporation provides the following data on a proposed capital.pdfaucmistry
ย 
HAROUN COMPANY Comparative Year-End Balance Sheets December 31, 2021.pdf
HAROUN COMPANY Comparative Year-End Balance Sheets December 31, 2021.pdfHAROUN COMPANY Comparative Year-End Balance Sheets December 31, 2021.pdf
HAROUN COMPANY Comparative Year-End Balance Sheets December 31, 2021.pdfaucmistry
ย 
HAPTER 9 - Other Income, Other Deductions and Other IssuesIntroduc.pdf
HAPTER 9 - Other Income, Other Deductions and Other IssuesIntroduc.pdfHAPTER 9 - Other Income, Other Deductions and Other IssuesIntroduc.pdf
HAPTER 9 - Other Income, Other Deductions and Other IssuesIntroduc.pdfaucmistry
ย 
HAP 417Watch the following 4 videos and then answer the 6 question.pdf
HAP 417Watch the following 4 videos and then answer the 6 question.pdfHAP 417Watch the following 4 videos and then answer the 6 question.pdf
HAP 417Watch the following 4 videos and then answer the 6 question.pdfaucmistry
ย 

More from aucmistry (20)

Consider the Project article 2 titled Readiness for Organizational .pdf
 Consider the Project article 2 titled Readiness for Organizational .pdf Consider the Project article 2 titled Readiness for Organizational .pdf
Consider the Project article 2 titled Readiness for Organizational .pdf
ย 
Consider the pedigree for Waardenburg syndrome which is an autosomal .pdf
 Consider the pedigree for Waardenburg syndrome which is an autosomal .pdf Consider the pedigree for Waardenburg syndrome which is an autosomal .pdf
Consider the pedigree for Waardenburg syndrome which is an autosomal .pdf
ย 
Consider the imaginary nation of Leguminia, whose citizens only consu.pdf
 Consider the imaginary nation of Leguminia, whose citizens only consu.pdf Consider the imaginary nation of Leguminia, whose citizens only consu.pdf
Consider the imaginary nation of Leguminia, whose citizens only consu.pdf
ย 
Consider the investment projects in the table below, all of which hav.pdf
 Consider the investment projects in the table below, all of which hav.pdf Consider the investment projects in the table below, all of which hav.pdf
Consider the investment projects in the table below, all of which hav.pdf
ย 
Consider the following method. Answer the following 1. Describe the w.pdf
 Consider the following method. Answer the following 1. Describe the w.pdf Consider the following method. Answer the following 1. Describe the w.pdf
Consider the following method. Answer the following 1. Describe the w.pdf
ย 
Consider the following statistics From 2010 to 2011 GDP grew by 2.3.pdf
 Consider the following statistics From 2010 to 2011 GDP grew by 2.3.pdf Consider the following statistics From 2010 to 2011 GDP grew by 2.3.pdf
Consider the following statistics From 2010 to 2011 GDP grew by 2.3.pdf
ย 
Consider the following table I am trying to do a substring on SELECT.pdf
 Consider the following table I am trying to do a substring on SELECT.pdf Consider the following table I am trying to do a substring on SELECT.pdf
Consider the following table I am trying to do a substring on SELECT.pdf
ย 
Consider the following closed economy, C=480+0.8(YT),Pp=100,G=20, w.pdf
 Consider the following closed economy, C=480+0.8(YT),Pp=100,G=20, w.pdf Consider the following closed economy, C=480+0.8(YT),Pp=100,G=20, w.pdf
Consider the following closed economy, C=480+0.8(YT),Pp=100,G=20, w.pdf
ย 
Consider the data for the mean number of days with precipitation more.pdf
 Consider the data for the mean number of days with precipitation more.pdf Consider the data for the mean number of days with precipitation more.pdf
Consider the data for the mean number of days with precipitation more.pdf
ย 
Consider the following documents Doc 1 pat sat on mat Doc 2 cat sa.pdf
 Consider the following documents Doc 1 pat sat on mat Doc 2 cat sa.pdf Consider the following documents Doc 1 pat sat on mat Doc 2 cat sa.pdf
Consider the following documents Doc 1 pat sat on mat Doc 2 cat sa.pdf
ย 
Consider the continuous random variable, Y, with moment generating fu.pdf
 Consider the continuous random variable, Y, with moment generating fu.pdf Consider the continuous random variable, Y, with moment generating fu.pdf
Consider the continuous random variable, Y, with moment generating fu.pdf
ย 
Consider the case in which query involves a single variable. Let X be.pdf
 Consider the case in which query involves a single variable. Let X be.pdf Consider the case in which query involves a single variable. Let X be.pdf
Consider the case in which query involves a single variable. Let X be.pdf
ย 
Haz un resumen del siguiente pasaje y dale un t๏ฟฝtulo adecuado. Has.pdf
Haz un resumen del siguiente pasaje y dale un t๏ฟฝtulo adecuado. Has.pdfHaz un resumen del siguiente pasaje y dale un t๏ฟฝtulo adecuado. Has.pdf
Haz un resumen del siguiente pasaje y dale un t๏ฟฝtulo adecuado. Has.pdf
ย 
Hay nueve filos principales descritos -Referencias - Mollusca, P.pdf
Hay nueve filos principales descritos -Referencias - Mollusca, P.pdfHay nueve filos principales descritos -Referencias - Mollusca, P.pdf
Hay nueve filos principales descritos -Referencias - Mollusca, P.pdf
ย 
Have you ever driven through a rural area and thought, There is not.pdf
Have you ever driven through a rural area and thought, There is not.pdfHave you ever driven through a rural area and thought, There is not.pdf
Have you ever driven through a rural area and thought, There is not.pdf
ย 
Harvey Inc. has a Current E&P balance of ($100,000) earned ratably t.pdf
Harvey Inc. has a Current E&P balance of ($100,000) earned ratably t.pdfHarvey Inc. has a Current E&P balance of ($100,000) earned ratably t.pdf
Harvey Inc. has a Current E&P balance of ($100,000) earned ratably t.pdf
ย 
Harris Corporation provides the following data on a proposed capital.pdf
Harris Corporation provides the following data on a proposed capital.pdfHarris Corporation provides the following data on a proposed capital.pdf
Harris Corporation provides the following data on a proposed capital.pdf
ย 
HAROUN COMPANY Comparative Year-End Balance Sheets December 31, 2021.pdf
HAROUN COMPANY Comparative Year-End Balance Sheets December 31, 2021.pdfHAROUN COMPANY Comparative Year-End Balance Sheets December 31, 2021.pdf
HAROUN COMPANY Comparative Year-End Balance Sheets December 31, 2021.pdf
ย 
HAPTER 9 - Other Income, Other Deductions and Other IssuesIntroduc.pdf
HAPTER 9 - Other Income, Other Deductions and Other IssuesIntroduc.pdfHAPTER 9 - Other Income, Other Deductions and Other IssuesIntroduc.pdf
HAPTER 9 - Other Income, Other Deductions and Other IssuesIntroduc.pdf
ย 
HAP 417Watch the following 4 videos and then answer the 6 question.pdf
HAP 417Watch the following 4 videos and then answer the 6 question.pdfHAP 417Watch the following 4 videos and then answer the 6 question.pdf
HAP 417Watch the following 4 videos and then answer the 6 question.pdf
ย 

Recently uploaded

Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
ย 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
ย 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
ย 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
ย 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
ย 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
ย 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
ย 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
ย 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
ย 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
ย 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
ย 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
ย 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
ย 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
ย 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
ย 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
ย 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
ย 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
ย 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
ย 

Recently uploaded (20)

Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
ย 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
ย 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
ย 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
ย 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
ย 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
ย 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
ย 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
ย 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
ย 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
ย 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
ย 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
ย 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
ย 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
ย 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
ย 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
ย 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
ย 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
ย 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
ย 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
ย 

Given the code below create a method called, getCollisionCount that .pdf

  • 1. Given the code below create a method called, getCollisionCount that will return the number of collisions that occurred. This method will be inside the hasedDictionary class. Please do not use setNext getNext methods or any nodes just use what's provided in the code below import java.util.Iterator; public interface DictionaryInterface { /** Adds a new entry to this dictionary. If the given search key already exists in the dictionary, replaces the corresponding value. @param key An object search key of the new entry. @param value An object associated with the search key. @return Either null if the new entry was added to the dictionary or the value that was associated with key if that value was replaced. */ public V add(K key, V value); /** Removes a specific entry from this dictionary. @param key An object search key of the entry to be removed. @return Either the value that was associated with the search key or null if no such object exists. */ public V remove(K key); /** Retrieves from this dictionary the value associated with a given search key. @param key An object search key of the entry to be retrieved. @return Either the value that is associated with the search key or null if no such object exists. */ public V getValue(K key); /** Sees whether a specific entry is in this dictionary. @param key An object search key of the desired entry. @return True if key is associated with an entry in the dictionary. */ public boolean contains(K key); /** Creates an iterator that traverses all search keys in this dictionary. @return An iterator that provides sequential access to the search keys in the dictionary. */ public Iterator getKeyIterator(); /** Creates an iterator that traverses all values in this dictionary.
  • 2. @return An iterator that provides sequential access to the values in this dictionary. */ public Iterator getValueIterator(); /** Sees whether this dictionary is empty. @return True if the dictionary is empty. */ public boolean isEmpty(); /** Gets the size of this dictionary. @return The number of entries (key-value pairs) currently in the dictionary. */ public int getSize(); /** Removes all entries from this dictionary. */ public void clear(); } // end DictionaryInterface //hasheddictionay class import java.util.Iterator; import java.util.NoSuchElementException; /** * A class that implements the ADT dictionary by using hashing and * linear probing to resolve collisions. * The dictionary is unsorted and has distinct search key. Search keys and associated values are not null. */ public class HashedDictionary implements DictionaryInterface { // The dictionary: private int numberOfEntries; private static final int DEFAULT_CAPACITY = 5; // Must be prime private static final int MAX_CAPACITY = 10000; // The hash table: private Entry[] hashTable; private int tableSize; // Must be prime private static final int MAX_SIZE = 2 * MAX_CAPACITY; private boolean integrityOK = false; private static final double MAX_LOAD_FACTOR = 0.5; // Fraction of // hash table that can be filled
  • 3. protected final Entry AVAILABLE = new Entry<>(null, null); public HashedDictionary() { this(DEFAULT_CAPACITY); // Call next constructor } // end default constructor public HashedDictionary(int initialCapacity) { initialCapacity = checkCapacity(initialCapacity); numberOfEntries = 0; // Dictionary is empty // Set up hash table: // Initial size of hash table is same as initialCapacity if it is prime; // otherwise increase it until it is prime size tableSize = getNextPrime(initialCapacity); checkSize(tableSize); // Check that size is not too large // The cast is safe because the new array contains null entries @SuppressWarnings("unchecked") Entry[] temp = (Entry[])new Entry[tableSize]; hashTable = temp; integrityOK = true; } // end constructor /* Implementations of methods in DictionaryInterface are here. . . .*/ public boolean isEmpty() { return this.numberOfEntries == 0; }//end isEmpty public Iterator getValueIterator() { throw new NoSuchElementException("Value Iterator Not Implemented");
  • 4. }//end valueIterator public void clear() { checkIntegrity(); for (int index = 0; index < this.hashTable.length; index++) { hashTable[index] = null; }//end of for this.numberOfEntries = 0; }//end clear public Iterator getKeyIterator() { return new KeyIterator(); }//end iterator public boolean contains(K key) { return getValue(key) != null; }//end contains public int getSize() { return this.numberOfEntries; }//end getSize public V remove(K key) { checkIntegrity(); int index = getHashIndex(key); while (hashTable[index] != null) { if (hashTable[index].getKey().equals(key)) { V value = hashTable[index].getValue(); hashTable[index].setValue(null); hashTable[index] = AVAILABLE;
  • 5. numberOfEntries--; return value; } index = (index + 1) % hashTable.length; } // If the key is not found, return null return null; } public V getValue(K key) { checkIntegrity(); V result = null; int index = getHashIndex(key); if ((hashTable[index] != null) && (hashTable[index] != AVAILABLE)) result = hashTable[index].getValue(); // Key found; get value // Else key not found; return null return result; } // end getValue public V add(K key, V value) { int index; V oldValue; if((key == null) || (value == null)) { throw new NoSuchElementException(); } index = getHashIndex(key); if((hashTable[index] != null) && (hashTable[index] != AVAILABLE)) { hashTable[index] = new Entry(key,value); numberOfEntries++; oldValue = null;
  • 6. } else { oldValue = hashTable[index].getValue(); hashTable[index].setValue(value); } if(isHashTableTooFull()) { enlargeHashTable(); } return oldValue; }//end of add /* END of Implementations of dictionary methods are here^. . . . */ /* Implementations of private methods are here. . . . */ //precondition: checkIntegrity has been called private void enlargeHashTable() { Entry[] oldTable = hashTable; int oldSize = hashTable.length; int newSize = getNextPrime(oldSize + oldSize); checkSize(newSize); //The cast is safe because the new array contains null entries @SuppressWarnings("unchecked") Entry[] temp = (Entry[]) new Entry[newSize]; hashTable = temp; numberOfEntries = 0;//reset number of dictionary entries, since it will be incremented by add during rehash //rehash dictionary entries from old array to the new and bigger array; //skip elements that contain null or available
  • 7. for(int index = 0; index < oldSize; index++) { if((oldTable[index] != null) && (oldTable[index] != AVAILABLE)) { add(oldTable[index].getKey(), oldTable[index].getValue()); } }// end for }//end enlargeHashTable private int getHashIndex(K key) { int hashIndex = key.hashCode() % hashTable.length; if(hashIndex < 0) { hashIndex = hashIndex + hashTable.length; } return hashIndex; }//end getHashIndex private void checkIntegrity() { if(!integrityOK) { throw new SecurityException("objecy is currupt"); } }//end checkIntegrity private boolean isHashTableTooFull() { if((numberOfEntries / hashTable.length) >= MAX_LOAD_FACTOR) {
  • 8. return true; } else { return false; } }//end isHashTableTooFull private int checkSize(int size) { if(size >= MAX_SIZE){throw new IllegalStateException("Dictionary has become too large.");} else{return size;} }//end checksize private int checkCapacity(int cap) { if(cap < DEFAULT_CAPACITY) { cap = DEFAULT_CAPACITY; } else if (cap > MAX_CAPACITY) { throw new IllegalStateException("Attempt to create a dictionary " + "whose capacity is larger than " + MAX_CAPACITY); } return cap; }//end checkcap private int getNextPrime(int integer) {
  • 9. // if even, add 1 to make od if (integer % 2 == 0) { integer++; } // end if // test odd integers while (!isPrime(integer)) { integer = integer + 2; } // end while return integer; }//end getnextprime private boolean isPrime(int integer) { boolean result; boolean done = false; // 1 and even numbers are not prime if ( (integer == 1) || (integer % 2 == 0) ) { result = false; } // 2 and 3 are prime else if ( (integer == 2) || (integer == 3) ) { result = true; } else // integer is odd and >= 5 { assert (integer % 2 != 0) && (integer >= 5); // a prime is odd and not divisible by every odd integer up to its square root result = true; // assume prime for (int divisor = 3; !done && (divisor * divisor <= integer); divisor = divisor + 2) {
  • 10. if (integer % divisor == 0) { result = false; // divisible; not prime done = true; } // end if } // end for } // end if return result; } // end isPrime /* END of Implementations of private methods are here^. . . . */ protected final class Entry { private K key; private V value; private Entry(K searchKey, V dataValue) { key = searchKey; value = dataValue; }//end contructor private K getKey() { return key; }//end getKey private V getValue() { return value; }//end value private void setValue(V newValue) { value = newValue; }//end setValue
  • 11. } // end Entry private class KeyIterator implements Iterator { private int currentIndex; // Current position in hash table private int numberLeft; // Number of entries left in iteration private KeyIterator() { currentIndex = 0; numberLeft = numberOfEntries; } // end default constructor public boolean hasNext() { return numberLeft > 0; } // end hasNext public void remove() { throw new UnsupportedOperationException(); } // end remove public K next() { K result = null; if (hasNext()) { // Skip table locations that do not contain a current entry while ( (hashTable[currentIndex] == null) || (hashTable[currentIndex] == AVAILABLE) ) { currentIndex++; } // end while result = hashTable[currentIndex].getKey(); numberLeft--; currentIndex++; }
  • 12. else throw new NoSuchElementException(); return result; } // end next } // end KeyIterator } // end HashedDictionary