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

HashEntry.java /* * To change this template, choose Tools | Templates * and open

ID: 3702881 • Letter: H

Question

HashEntry.java

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

public class HashEntry {

private int key;

private String value;

HashEntry(int key, String value) {

this.key = key;

this.value = value;

}

public int getKey() {

return key;

}

public String getValue() {

return value;

}

  

public void setValue(String val) {

this.value = val;

}

}

HashMap.java

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

public class HashMap {

private final static int TABLE_SIZE = 137;

HashEntry[] table;

HashMap() {

   //Implement

}

public String get(int key) {

// Implement

}

public void put(int key, String value) {

   // Implement

}

public void linearProbe(int key, String value){

   // Implement

}

public void quadraticProbe(int key, String value){

   // Implement

}

}

input.txt

79,,INDIANA LOTTO
93,,treo 700w
123,,Wrsi Riversound cafe cd
161,,Dillons/Kroger Employee Coupon ($1.25 credit)
2140000070,,Rhinestone Watch
2140118461,,"""V"": Breakout/The Deception VHS Tape"
2144209103,VHS,Tintorera - Tiger Shark
2144622711,,Taxi : The Collector's Edition VHS
2147483647,,Toshiba 2805 DVD player
2158242769,288/1.12Z,GREEN SUGAR COOKIES4276
2158561631,,HOT COCOA W/BKMK
2158769549,njhjhn,gjfhjbgkj
2160500567,2.25 oz (64)g,Dollar Bar Rich Raspberry
2172307284,,Mixed seasonal flower bouquet
2177000074,,4 way 13 AMP Extension Lead (Wilkinson UK)
2184000098,21 oz,Christopher's Assorted Fruit Jellies
2187682888,,fairway

upc.csv

79 INDIANA LOTTO 93 treo 700w 123 Wrsi Riversound cafe cd 161 Dillons/Kroger Employee Coupon ($1.25 credit) 178 Outdoor Bag 1090 VAR Rountech Asset 1 1205 1 gal GIANT NATURAL MOUNTAIN SPRING WATER 1243 CVS Photo 1-Hour 4x6 Finishing 1601 Sainsbury's Red Pepper 2288 18 oz Winn Dixie Hand Lotion 2745 sunglasses 4138 100 pack Taiyo-Yuden Value Line 8x DVD-R 4145 7.6 cm x 1.8m Conforming Bandages 5210 maggi 6217 1 gal Trader Joe's 1% Lowfat Milk 7511 44 oz Maverik Plastic Soda Cup 8570 jewerly 9997 32 FL OZ Down to Earth - Goji Berry Juice 10016 16.9 oz Coupon 10023 1.3 - 2.2 oz Coupon 10344 CD WNCI Morning Zoo - Oops... We Did It Again! 14946 6.5mm thick - 3m roll Florist Ribbon - Lemon Yellow 28523 Coupon for $1.00 off Spareribs, Wegmans Rochester 29438 16 FL OZ. (1 pt) 473ML Trader Joe's Energy Drink Wild Berry 40112 Variable Weight Bananas 42215 Small Avacados - Green 43816 1.76 oz Altoids/ Peppermint 46268 JICAMA 49887 1 x 8 oz Coca Cola:Diet Coke 50340 12057 2X72X150 POULTRY NETTING 52559 17.5 oz Raid Ant & Roach Spray 54607 Engizer e2 Batteries 56731 3/8X1.5X48 POINT LATH STAKE 56748 3/8X1.5X48 WD PLASTER LATH 58322 10 oz (284g) Trader Joe's Dark Chocolate Covered Macadamia Nuts 61315 Paper Money-Saving Coupon for Walgreens One-Hour Photo Center; Process 2 rolls, get the 3rd FREE with One Hour Service Any 35 mm film or one-time use camera 61322 Paper Money-Saving Coupon for Walgreens One-Hour Photo Center; Process 1 roll, get the 2nd 50%off with One Hour Service Any 35 mm or one-time use camera 61339 4 Way Smoothing Block Nail Buffer 61537 Park Seeds Tumbling Topm Tomato Seeds, packet of 20 63425 1,5L Sainsbury's HOCK (Deutscher Tafelwein Rhein) 66419 854000 LUMBER CRAYON HOLDER 68529 Gian Eagle $5 Off seafood Purchase 72342 WAVELINE NON/ASBESTOS SHINGLE 72359 STRT EDGE NON ASBESTOS SHINGLE 89906 16 oz (1 lb) 454g Trader Joe's Pacific Northwest Super Sweet Cut White Corn (frozen) 93699 8.fHmg.C3PWDxP6Ca. 94122 7 oz. Original Sesame Thins, Trader Joe's 98601 00414 9GA GALV 50# SMOOTH WIRE 98632 00426 12GA 50# GLV SMOOTH WIRE 98649 00434 14GA 50# GLV SMOOTH WIRE Use the Java source files HashEntry.java and HashMap.java provided in canvas. Create a hash table that is made of elements HashElement(int Key, String Value) The size of hash table will be 137. Implement the following methods for the hash table: a. put(int Key, String Value): Puts the key value pair in the hash table at a certain index You need to implement a simple hash function H(key)-key mod mapsize to find the index where you will put the pair. 11. iii. If collision occurs, i.e., a pair already exists in that index and the key is not the same as the current key, then you will use this function to resolve the collision, H(key)-(7*H(key)+1) mod mapsize, until you get an empty slot. iv. If the index is already full and the keys are the same, just replace the old value with the new one.

Explanation / Answer

use the Java source filesHashEntry.java and HashMap.java provided in canvas.   

*(a)Create a hashtable that is made of elements HashElement(int Key, String Value)The size of hash table will be 137. Implement the following methodsfor the hash table: a. put(int Key, String Value):

(1). Puts the keyvalue pair in the hash table at a certain index.

(2). You need toimplement a simple hash function H(key) = key mod mapsize to findthe index where you will put the pair. 11.

(3). If collisionoccurs, i.e., a pair already exists in that index and the key isnot the same as the current key, then you will use this function toresolve the collision, H(key)-(7*H(key)+1) mod mapsize, until youget an empty slot.

(4). If the index is already full and the keys are thesame, just replace the old value with the new one.

===HashMap===

import java.math.BigInteger;

public class HashMap {

private final static int TABLE_SIZE = 137;

HashEntry[] table;

HashMap() {

table = newHashEntry[TABLE_SIZE];

for (int i = 0; i < TABLE_SIZE;i++)

table[i] =null;

}

public String get(int key) {

int hash = newBigInteger(toAscii(key)).mod(new BigInteger(((Integer)TABLE_SIZE).toString())).intValue();

while (table[hash] != null&& table[hash].getKey() != key)

hash = ((7 *hash) + 1) % TABLE_SIZE;

if (table[hash] == null)

returnnull;

else

returntable[hash].getValue();

}

public void put(int key, String value) {

// creating hash code using keyvalue given as a string

int hash = newBigInteger(toAscii(key)).mod(new BigInteger(((Integer)TABLE_SIZE).toString())).intValue();

while (table[hash] != null&& table[hash].getKey() != key)

hash = ((7 *hash) + 1) % TABLE_SIZE;

table[hash] = new HashEntry(key,value);

}

public void linearProbe(int key, String value){

// Implement

}

public void quadraticProbe(int key, String value){

// Implement

}

public static String toAscii(int value) {

String s =String.valueOf(value);

StringBuilder sb = newStringBuilder();

long asciiInt;

// loop through all values in thestring, including blanks

for (int i = 0; i < s.length();i++) {

// getting Asciivalue of character and adding it to the string.

char c =s.charAt(i);

asciiInt = (int)c;

sb.append(asciiInt);

}

return String.valueOf(sb);

}

}

Main Fuction

import java.io.IOException;

public class HashTable {

public static void main(String[] args) throwsIOException {

HashMap entry = newHashMap();

entry.put(36100, "Dipal");

entry.put(52120, "Hemant");

entry.put(22100, "Harleen");

System.out.println(entry.get(52120));

entry.put(12345, "John");

System.out.println(entry.get(12345));

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote