At this point, you decide to implement a Hash structure for the contributor data to prepare for searches. You will read the contributor information from a file provided; it is a comma delimited (CSV)...

1 answer below »

At this point, you decide to implement a Hash structure for the contributor data to prepare for searches. You will read the contributor information from a file provided; it is a comma delimited (CSV) file. As each record is read, create a Hash table for the ID field. The limitation for the Hash table is that it has a size of 5, so you need to be able to handle collisions. Collisions should be resolved through the use of a linked list for the ID values (implement this using a stack). Your design should include the following:


A Hash table pointing to a structure for a linked list that contains only the following information:


Each Hash Bucket Collision Item will have the following Information:



  • ID: Integer; //identifier key for future needs



Hash Bucket Functions/Methods:



  • Input constructor: //to accept a string for the name and additional information for each contributor (you will only need the ID portion of the input data)

  • Hash Function constructor: (Hint: You only have 5 Hash buckets, so the function can be a very simple calculation.)

  • Pop constructor

  • Push constructor

  • Print constructor: //to show the contents of a Hash bucket



Deliverables:



  • A fully documented program to load the Hash table with collisions being handled as a linked list, implemented as a Stack

  • A test plan to show how the program runs and can be executed

  • A screenshot showing that the program loaded the data, and after all data is loaded, shows the contents of the first Hash bucket (ideally this is Bucket 0)



Please submit your assignment.

Answered Same DayDec 01, 2021

Answer To: At this point, you decide to implement a Hash structure for the contributor data to prepare for...

Sudipta answered on Dec 03 2021
152 Votes
import java.util.Scanner;
import java.io.File;
import java.util.regex.Pattern;
public class ContributorManager {
    public static void main(String [] a
rgs) {
        Scanner inputFile = null;
        String name = null;
        String city = null;
        String country = null;
        String phone = null;
        double contribution = 0;
        int id = 0;
        Contributor c = null;
        Node node = null;
        HashTable h = new HashTable(5);

        //open contributors file
        try {
            inputFile = new Scanner(new File("contributors.csv"));
            inputFile.useDelimiter(Pattern.compile("(\\n)|(\\r)|,"));
        }
        catch (Exception e) {
            System.err.println("Error opening file.");
        }
        //create contributors object for each row, and add to the stack
        while (inputFile.hasNext()) {
            name = inputFile.next();
            city = inputFile.next();
            country = inputFile.next();
            phone = inputFile.next();
            contribution = inputFile.nextDouble();
            id = inputFile.nextInt();
            inputFile.nextLine(); //advance to the next line

            c = new Contributor(name, city, country, phone, contribution, id);
            node = new Node(c);
            h.insert(node); //insert node into the hash table
        }

        h.print(); //print the entire hash table
    }
}
public class Contributor {
    private String name;
    private String city;
    private...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here