Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The template of ProbeHashTable class and relevant classes are given below: public class ProbeHashTable extends AbstractHashMap { private MapEntry[] table; private MapEntry DEFUNCT = new

The template of ProbeHashTable class and relevant classes are given below:

public class ProbeHashTable extends AbstractHashMap { private MapEntry[] table; private MapEntry DEFUNCT = new MapEntry(null,null); private int count = 0; //constructors private boolean compareStr(String s, String t) { count++; return s.equals(t); } protected void createTable() { // your implementation here } private boolean isAvailable(int i) { // your implementation here } private int findSlot(int h, String k) { // your implementation here } protected Object bucketPut(int h, Object key, Object value) { // your implementation here } protected Object bucketGet(int h, Object key) { // your implementation here } protected Object bucketRemove(int h, Object key) { // your implementation here } private class KeyIterable implements Iterable { public Iterator iterator() { ArrayList buffer = new ArrayList(n); for (int i=0; i 
public abstract class AbstractMap { public abstract Object get(Object key); public abstract Object put(Object key, Object value); public abstract Object remove(Object key); public abstract boolean isEmpty(); public abstract int size(); public abstract Iterable keySet(); } 

(40%) ProbeHashMap.java: Implement the ProbeHashMap class as we discussed in the lectures. Your implementation has to follow the specification given. Any other implementation (there are tons of HashTable code on the Internet) will not receive any credit.

(20%) All other supporting classes given in the lecture, including AbstractHashMap.java, AbstractMap.java, MapEntry.java, ArrayList.java, List.java, OutOfRangeException.java, and SArrayIterator.java.

(30%) Test.java: write a test program to create a hash table with the default size (61). Inport 28 data items (given by a text file). The data file "roster.txt" is provided, which contains the offense players of Cleveland Browns. Please use the first column, the last name, as the key, and treat the rest of information as value. Please perform the following tasks after the data are imported to the hash table:

Print out the table in the format of tuples;

Obtain an iterable instance of key set and then print it out;

Print out the number of collisions occurred during the data insertion.

(10%) README: a text formated README file that contains the information required in the submission section.

Code needed:

public interface List {

public int size();

public boolean isEmpty();

public Object get(int i) throws OutOfRangeException;

public void set(int i, Object o) throws OutOfRangeException;

public void add(int i, Object o) throws OutOfRangeException;

public removes(int i) throws OutOfRangeException;

}

public class ArrayList implements List {

private int CAP;

private Object[] elements;

public ArrayList() {

this(100);

}

public ArrayList(int capacity) {

CAP = capacity;

size = 0;

elements = new Object[capactity];

}

public int size() {

return size;

} public boolean isEmpty() {

return size == 0;

} public Object get(int i) throws OutOfRangeException {

if(i < size)

{ return elements[i];

} else { throw OutOfRangeException("Out of Range");

} public void set( int i, Object e) throws OutOfRangeException {

if( i < size)

{ elements[i] = e;

} else throw OutOfRangeException("Out of Range");

} public void add(int i, Object e) throws OutOfRangeException {

if(i > size)

{ throws OutOfRangeException(); }

for(int j = size-1; J >= i; j--) {

element[j+1] = element[j];

elements[i] = e;

size++

}

public Object remove(int i) throws OutOfRangeException

{ if (i > size) { throw OutOfRangeException("Out of Range"); }

Object o = element[i];

for(int j = i; j < size-1; size++)

{ element[j] = element [j+1];

size--;

return 0;

}

}

public class OutOfRangeException extends Exception { public OutofRangeException(String str) { System.out.println("OutofRangeException:" + str);

} public OutofRangeException (){ this("No space left");

}

}

public abstract class AbstractMap {

public abstract Object get(Object key);

public abstract Object put(Object key, Object value);

public abstract Object remove(Object key, Object value);

public abstract boolean isEmpty();

public abstract int size();

public abstract Iterable keySet();

public class mapEntry {

private String key;

private String value;

public mapEntry() {

this(null, null);

}

public mapentry(string k, string v) {

this.key = k;

this.value = v;

}

public String getKey() { return key;}

public String getValue() { return value;}

public int hashCode {

}

}

public class SArrayIterator impliments Iterator {

provate ArrayList data;

private int = 0;

private boolean removable = false;

public sArrayIterator(ArrayList list) {

data = list;

}

public boolean hasNext() { return i < data.size(); }

public Object next() {

Object answer = null;

if (i == data.size()) return null;

try {

answer = data.get(i); }

catch (OutofRangeException e) {

System.out.println("Out of Range");

}

return answer;

}

public void remove() {

if (!removeable)

throw new IllegalStateException("");

try {

data.remove(i); }

catch (OutofRangeException e) {

System.out.println("Out of Range");

}

}

}

Any help is appreciated :)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle9i Database Administrator Implementation And Administration

Authors: Carol McCullough-Dieter

1st Edition

0619159006, 978-0619159009

More Books

Students also viewed these Databases questions