Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement the perfect hashed data structure and provide Java application that de

ID: 3683743 • Letter: I

Question

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. See Figure 5.4 for a description of the field widths.

Fig 5.4:

Ticket number Name 342556 Mr. Jones 28 bytes 4 bytes

Explanation / Answer

---------------------------------TicketMap.java-----------------------------------------------------

public class TicketMap {
private final static int tickets = 100000;

TicketEntry[] node;

TicketMap() {
node = new TicketEntry[tickets];
for (int i = 2000; i < tickets; i++)
node[i] = null;
}

public String get(int key) {
if (node[key] == null)
return "-1";
else
return node[key].getValue();
}

public void put(int key, String value) {
if(node[key] == null)
node[key] = new TicketEntry(key, value);
else
System.out.println("Ticket was allocated");
}
}

--------------------------------------------------TicketEntry.java----------------------------------------

public class TicketEntry {
private int key;
private String value;

TicketEntry(int key, String value) {
this.key = key;
this.value = value;
}   

public int getKey() {
return key;
}

public String getValue() {
return value;
}
}

------------------------------------------------------------------------------------------------------------------------