Question: Need help with java program. Hashtable Your Hashtable should support some basic methods It should have a put method it should have a get method
Need help with java program. Hashtable
Your Hashtable should support some basic methods
It should have a put method
it should have a get method
it should have a constructor
it should have a remove method
it needs to be generic so that you can decide the the type of the objects stored in the array the hashtable uses for reference.
You don't want anyone changing your fields. You only need to give the user the functionality required which are put, get, the constructor. All your methods and fields should either be private or protected with the exception of constructors and the other methods needed for interaction.
The constructor needs to be public
The put (key, value) method needs to be public
The get (key) method needs to be public
The remove (key) method needs to be public
It can only take complex numbers as it's key
You will need to write a hash function for the complex numbers
Hasfunction(myComplexNum)% arraysizeAlternatively you can build the method to look like this
Hasfunction(myComplexNum, arraysize)
the size of the array which we will stores the values in needs to be prime
You will need to get the next prime number and make a new array every time your hash table has more than 70% of it's elements populated, You will then need to transfer all your old elements into that new array taking into account that the elements will need a new indexes because we will module by a different array size.
You need to implement chaining for each bucket in the array.
You can either use a generic implementation (such as an arraylist or sets) or you can use your own linked list, or a tree (for better performance)
Each bucket should hold a reference to it's value and it's key (two references)
You will need to implement the comparable interface for both complex numbers and the buckets if you use a tree like structure for chaining
Complex: toString() getHash() isEqual.
Bucket
Hashmap: dictionary; int size; ArrayList
Program:
public class Bucket
Complex key ;
Value value;
Bucket(Complex key, Value value){
this.key = key;
this.value = value;
}
Bucket (){
this.key = new Complex(0,0);
this.value = null;
}
//getValue()
//getKey()
//isKeyEqual()
//getHashValue()
//ChangeValue()
}
public class Complex {
double real;
double imag;
int toHash() {
string rep = this.toString;
//for ( i to End of String)
}
String toString() {
String result = real;
if(imag > 0) {
return result += "+" imag + "i";
}else {
return += "-" + imag + "i";
}
hash *= NumberAsk;
hash += Askifchar[i];
}
}
public class Hashmap
ArrayList < LinkedListt
Storage ;
boolIsEqual(Complex a)
{
return ((this.real== a.real)&&(this.imag==a.imag));
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
