Implement the perfect hashed data structure and provide Java
Implement the perfect hashed data structure and provide Java application that demonstrates that its four basic operation methods function properly. Your application should store nodes for a stadium ticket application where the ticket numbers range from 2000 to 100,000 for a 60,000 seat stadium. The ticket number will be the key field and the nodes will also store the purchaser\'s name.
Solution
import java.util.Hashtable;
import java.util.Scanner;
public class Application {
static Hashtable<Integer, String> ticket= new Hashtable<Integer, String>(60000);
public static void main(String str[])
{
int n,number,i=0;
String name;
@SuppressWarnings(\"resource\")
Scanner sca=new Scanner(System.in);
System.out.println(\"Enter the number of element to enter in hash table\");
n=sca.nextInt();
System.out.println(\"Enter \"+n+\" elements and that should be between 2000 and 100000\");
while(i<n)
{
System.out.println(\"Enter the ticket number\");
number=sca.nextInt();
if(number>=2000 && number<=100000)
{
System.out.println(\"Enter the name\");
name=sca.next();
ticket.put(number,name);
i++;
}
else
{
System.out.println(\"Please enter the ticket number between 2000 and 100000\");
}
}
System.out.println(\"Enter the key value from which you want name\");
number=sca.nextInt();
System.out.println(ticket.get(number));
System.out.println(\"Number of elements in hashtable \"+ ticket.size());
System.out.println(\"check hash table is empty or not \");
System.out.println(ticket.isEmpty());
}
}
