Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This project is designed to help students to understand the HashTable and algorithms related to HashTable. The students need to implement two given classes: MyHashEntry

This project is designed to help students to understand the HashTable and algorithms related to HashTable. The students need to implement two given classes: MyHashEntry and MyHashTable.

Three classes are given. The students shall not modify the ProjThree.java file. However, the students should understand this file. The other two files, MyHashEntry.java and MyHashTable.java, are the files that the students need to finish.

These two files, MyHashEntry.java and MyHashTable.java, must be implemented within the given design. The students cannot change the name of public methods. Please notice that the table must be implemented as generic data structure.

The students may run the given executable jar file to see how the project should work. When the students run the executable jar file, the students may

enter pairs. Please notice that ID or Name are all Strings with no white space in it.

******************************ProjThree.java************************************ import java.util.Scanner; public class CSCI463ProjThree { public static void main(String args[]){ String value; String key; int choice; Scanner input = new Scanner(System.in); MyHashTable table = new MyHashTable(10); do{ menu(); System.out.print("Enter your choice: "); choice = input.nextInt(); switch(choice){ case 1: System.out.println("Enter an (Key, Value) pair that you will add to table "); System.out.print("Separate by white space: "); key = input.next(); value = input.next(); table.insert(key, value); System.out.println("(" + key + ", " + value + ") entered"); break; case 2: System.out.print("Enter a key that you will remvoe from table: "); key = input.next(); value = table.remove(key); if(value != null) System.out.println("Remove successfully. The removed value is " + value); else System.out.println("No such key in table"); break; case 3: System.out.print("Enter the key that you want to search for: "); key = input.next(); value = table.get(key); if(value == null) System.out.println("No such data in table"); else System.out.println("The corresponding value is: " + value); break; case 4: if(table.isEmpty()) System.out.println("table is empty"); else System.out.println(table); break; case 5: System.out.println("Make sure you run enough test before you turn it in"); break; default: System.out.println("Wrong option. Please choose from menu"); break; } }while(choice != 5); } private static void menu(){ System.out.println("********************************"); System.out.println("* MENU *"); System.out.println("* 1. Add a (key, value) pair *"); System.out.println("* 2. Remove a value by its key *"); System.out.println("* 3. Search a value by its key *"); System.out.println("* 4. Print out table *"); System.out.println("* 5. Quit *"); System.out.println("********************************"); } }

******************************MyHashEntry************************************

/** * class MyHashEntry. A Hash Entry as a single linked list Node */ public class MyHashEntry , V> { private K key; private V value; MyHashEntry next; /** * Constructor * @param key The key of MyHashEntry * @param value The value of myHashEntry */ public MyHashEntry(K key, V value){ } /** * get the key * @return the key of the ordered pair */ public K getKey(){ } /** * set the key for this ordered pair * @param key The key for this ordered pair */ public void setKey(K key){ } /** * get the value of this ordered pair * @return the value of this ordered pair */ public V getValue(){ } /** * set the value of this ordered pair * @param value the new value of this ordered pair */ public void setValue(V value){ } /** * set next entry for this entry * @param next A reference to the next entry */ public void setNext(MyHashEntry next){ } /** * get next entry * @return a reference to the next entry */ public MyHashEntry getNext(){ } }

******************************MyHashTable************************************

/** * class MyHashTable. A simple HashTable. Handle collision by chain * */ import java.util.ArrayList; public class MyHashTable, V> { private ArrayList> table; private int count; // how many elements in table /** * Constructor. Constructor an empty MyHashTable with given number of Buckets * @param tableSize The number of Buckets of the table */ public MyHashTable(int tableSize){ } /** * constructor. Construct an empty MyHashTable with capacity 10 buckets */ public MyHashTable(){ } /** * get the number of elements in the table * @return the number of elements in the table */ public int size(){ } /** * clear the table */ public void clear(){ } /** * get the value with given key. * @param key The given key * @return the value that have the key matches the given key. If no such a value, return null */ public V get(K key){ } /** * insert (key, value) pair into the table * @param key The key of the pair * @param value The value of the pair */ public void insert(K key, V value){ } /** * remove the value with given key from the table * @param key The given key * @return the value whose key matches the given key. If no such value, null is returned */ public V remove(K key){ } /** * check if the table is empty,i.e. no entry * @return true if the table holds no elements; false otherwise */ public boolean isEmpty(){ } /** * return a String representation of the table * @return a String representation of the table */ public String toString(){ } }

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2016 Riva Del Garda Italy September 19 23 2016 Proceedings Part 3 Lnai 9853

Authors: Bettina Berendt ,Bjorn Bringmann ,Elisa Fromont ,Gemma Garriga ,Pauli Miettinen ,Nikolaj Tatti ,Volker Tresp

1st Edition

3319461303, 978-3319461304

More Books

Students also viewed these Databases questions

Question

What is the maturity date of a bond?

Answered: 1 week ago