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

Having a lot of trouble understanding and even starting this assignment for abou

ID: 3759197 • Letter: H

Question

Having a lot of trouble understanding and even starting this assignment for about 5 days now (having an infant and toddler around make it especially hard, lol). I requested to have an extension for this assignment with no avail. I'm pretty desparate to get this done. Any help with this will be greatly appreciated! Thanks!
For this assignment you will create a class for counting occurrences of Strings. Effectively, this will be a hashmap from String to int. Do not use java.util.HashMap. Code must compile to be eligible for points. 10 point bonus: write a generic class that maps arbitrary keys to arbitrary values. Late work is not eligible for bonus points.
The StringCounter
Use the following class as a starting point for yours. Note that you are using the separate chaining collision resolution strategy, with a fixed table size - no rehashing is required. When you construct a new StringCounter you specify the table size and an object to use for hashing the strings.
public class StringCounter {
public interface HashFunction { int hash(String key); } private class Pair { public String key; public int count; }
private LinkedList<Pair>[] buckets; private HashFunction hasher;
@SuppressWarnings("unchecked") public StringCounter(int tableSize, HashFunction hasher) { buckets = (LinkedList<Pair>[]) new LinkedList<?>[tableSize]; this.hasher = hasher; }
public void increment(String word) {
}
public int getCount(String word) {
}
public void printStatistics() {
} public String mostCommonWord() { } }
Part 1
Write a program that uses this StringCounter to process all words in the provided words file (this file is a spell checking dictionary for unix systems), and calls the printStatistics() method to print out the following pieces of information:
1. total number of buckets 2. number of used and unused buckets 3. average size of non-empty buckets 4. maximum bucket size
Using a table size of 235886, run this program 3 times, with the 3 different hash functions as listed here. For each, collect the output of printStatistics():
1. Sum of ascii values of each String character 2. The horner’s rule-based hash function for English words (the one with the 37 in it). 3. A hash function of your own design.

Part 2
Use your StringCounter to count the words in the novel “Crime and Punishment”. Your program should print out the most common word in the novel, along with the number of times it appears. It should then prompt the user to enter words, one per line, and print out the number of times that word appeared in the novel.
Hints
Your keys should be case insensitive. Use the String method toLowerCase(). Use a java.util.Scanner to process the text file. The best way to break this file into individual words is to configure the Scanner with useDelimiter. I suggest using the delimiter “[^a-zA-Z]+”. This will cause the Scanner to discard all non-alphabetic characters. Having a lot of trouble understanding and even starting this assignment for about 5 days now (having an infant and toddler around make it especially hard, lol). I requested to have an extension for this assignment with no avail. I'm pretty desparate to get this done. Any help with this will be greatly appreciated! Thanks!
For this assignment you will create a class for counting occurrences of Strings. Effectively, this will be a hashmap from String to int. Do not use java.util.HashMap. Code must compile to be eligible for points. 10 point bonus: write a generic class that maps arbitrary keys to arbitrary values. Late work is not eligible for bonus points.
The StringCounter
Use the following class as a starting point for yours. Note that you are using the separate chaining collision resolution strategy, with a fixed table size - no rehashing is required. When you construct a new StringCounter you specify the table size and an object to use for hashing the strings.
public class StringCounter {
public interface HashFunction { int hash(String key); } private class Pair { public String key; public int count; }
private LinkedList<Pair>[] buckets; private HashFunction hasher;
@SuppressWarnings("unchecked") public StringCounter(int tableSize, HashFunction hasher) { buckets = (LinkedList<Pair>[]) new LinkedList<?>[tableSize]; this.hasher = hasher; }
public void increment(String word) {
}
public int getCount(String word) {
}
public void printStatistics() {
} public String mostCommonWord() { } }
Part 1
Write a program that uses this StringCounter to process all words in the provided words file (this file is a spell checking dictionary for unix systems), and calls the printStatistics() method to print out the following pieces of information:
1. total number of buckets 2. number of used and unused buckets 3. average size of non-empty buckets 4. maximum bucket size
Using a table size of 235886, run this program 3 times, with the 3 different hash functions as listed here. For each, collect the output of printStatistics():
1. Sum of ascii values of each String character 2. The horner’s rule-based hash function for English words (the one with the 37 in it). 3. A hash function of your own design.

Part 2
Use your StringCounter to count the words in the novel “Crime and Punishment”. Your program should print out the most common word in the novel, along with the number of times it appears. It should then prompt the user to enter words, one per line, and print out the number of times that word appeared in the novel.
Hints
Your keys should be case insensitive. Use the String method toLowerCase(). Use a java.util.Scanner to process the text file. The best way to break this file into individual words is to configure the Scanner with useDelimiter. I suggest using the delimiter “[^a-zA-Z]+”. This will cause the Scanner to discard all non-alphabetic characters. Having a lot of trouble understanding and even starting this assignment for about 5 days now (having an infant and toddler around make it especially hard, lol). I requested to have an extension for this assignment with no avail. I'm pretty desparate to get this done. Any help with this will be greatly appreciated! Thanks!
For this assignment you will create a class for counting occurrences of Strings. Effectively, this will be a hashmap from String to int. Do not use java.util.HashMap. Code must compile to be eligible for points. 10 point bonus: write a generic class that maps arbitrary keys to arbitrary values. Late work is not eligible for bonus points.
The StringCounter
Use the following class as a starting point for yours. Note that you are using the separate chaining collision resolution strategy, with a fixed table size - no rehashing is required. When you construct a new StringCounter you specify the table size and an object to use for hashing the strings.
public class StringCounter {
public interface HashFunction { int hash(String key); } private class Pair { public String key; public int count; }
private LinkedList<Pair>[] buckets; private HashFunction hasher;
@SuppressWarnings("unchecked") public StringCounter(int tableSize, HashFunction hasher) { buckets = (LinkedList<Pair>[]) new LinkedList<?>[tableSize]; this.hasher = hasher; }
public void increment(String word) {
}
public int getCount(String word) {
}
public void printStatistics() {
} public String mostCommonWord() { } }
Part 1
Write a program that uses this StringCounter to process all words in the provided words file (this file is a spell checking dictionary for unix systems), and calls the printStatistics() method to print out the following pieces of information:
1. total number of buckets 2. number of used and unused buckets 3. average size of non-empty buckets 4. maximum bucket size
Using a table size of 235886, run this program 3 times, with the 3 different hash functions as listed here. For each, collect the output of printStatistics():
1. Sum of ascii values of each String character 2. The horner’s rule-based hash function for English words (the one with the 37 in it). 3. A hash function of your own design.

Part 2
Use your StringCounter to count the words in the novel “Crime and Punishment”. Your program should print out the most common word in the novel, along with the number of times it appears. It should then prompt the user to enter words, one per line, and print out the number of times that word appeared in the novel.
Hints
Your keys should be case insensitive. Use the String method toLowerCase(). Use a java.util.Scanner to process the text file. The best way to break this file into individual words is to configure the Scanner with useDelimiter. I suggest using the delimiter “[^a-zA-Z]+”. This will cause the Scanner to discard all non-alphabetic characters.

Explanation / Answer

Part 2:

import java.awt.List;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class CandPHashSet
{
public static void main(String[] args) throws FileNotFoundException
{
Scanner file = new Scanner(new File("crime_and_punishment.txt"));
Set<String> crime = new HashSet<>();
while (file.hasNext())
{
crime.add(file.next().trim().toLowerCase());
}
System.out.println("Enter a word to search for: ");
Scanner input = new Scanner(System.in);
String search = input.next().toLowerCase();
if (crime.contains(search))
{
System.out.println("Yes");
}
else
{
System.out.println("No");
}

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