Computer science assignment about hash and heaps (data structure)

Attached are three files

1) assignment.word is the instruction

2) base code

3) mini tester

Get Help With a similar task to - Computer science assignment about hash and heaps (data structure)

Login to view and/or buy answers.. or post an answer
Additional Instructions:

package FinalProject; import java.util.ArrayList; /** * Class for testing your implementation of the HashTable class. */ public class HashTableTester { /** * Returns a list of tweets to use for testing the hash table. * @return A list of tweets to use for testing the hash table */ private static ArrayList<Tweet> initTweetList() { ArrayList<Tweet> tweets = new ArrayList<Tweet>(); tweets.add(new Tweet("USER_989b85bb","2010-03-04 15:34:46","@USER_6921e61d I can be made into one twitter superstar.")); tweets.add(new Tweet("USER_a75657c2","2010-03-03 00:02:54","@USER_13e8a102 They reached a compromise just on time")); tweets.add(new Tweet("USER_989b85bb","2010-03-04 15:34:47","I can be MADE into a need.")); tweets.add(new Tweet("USER_a75657c2","2010-03-07 21:45:48","So SunChips made a bag that is 100% biodegradeable. It is about damn time somebody did.")); tweets.add(new Tweet("USER_ee551c6c","2010-03-07 15:40:27","drthema: Do something today that feeds your spirit and empowers you to start the week from a higher place.")); tweets.add(new Tweet("USER_6c78461b","2010-03-03 05:13:34","@USER_a3d59856 yes, i watched that foolery done disturbed my spirit. @USER_b1d28f26")); tweets.add(new Tweet("USER_92b2293c","2010-03-04 14:00:11","@USER_5aac9e88: Let no one push u around today! Be at Peace! If u dont have restful spirit, u'll definitely have a stressful spirit")); tweets.add(new Tweet("USER_75c62ed9","2010-03-07 03:35:38","@USER_cb237f7f Congrats on everything I am there in spirit my brother.")); tweets.add(new Tweet("USER_7f72a368","2010-03-07 07:18:22","Actions speak louder than words but feelings and spirits speak louder than anything #FACT")); tweets.add(new Tweet("USER_b6cc1831","2010-03-07 04:04:37","@USER_be777094 urban spirit cafe. On Long st")); tweets.add(new Tweet("USER_65006b55","2010-03-05 00:58:28","RT @USER_86e8d97f: @USER_65006b55's spirit just took a turn for the worst. Lol please.")); tweets.add(new Tweet("USER_60b9991b","2010-03-04 22:33:23","Who on my time ever flew on spirit airlines let me kno if there decent")); tweets.add(new Tweet("USER_36607a99","2010-03-03 02:06:01","@USER_561fe280: Nourish your spirit with your own achievement.")); tweets.add(new Tweet("USER_9506fb5f","2010-03-04 01:16:34","Great spirits have often encountered violent opposition from weak minds")); tweets.add(new Tweet("USER_d3ca457f","2010-03-03 04:53:06","RT @USER_6d6bfb4d: The things that make a woman beautiful are her character, intellect, and spirituality.")); tweets.add(new Tweet("USER_14f78255","2010-03-03 17:07:45","@USER_9afbc367 Oh in spirit. That's all that matters lol")); tweets.add(new Tweet("USER_3dfae4fe","2010-03-05 00:44:33","time for a spiritual cleansing of my facebook friend list")); tweets.add(new Tweet("USER_bd852fb7","2010-03-03 14:19:51","RT @USER_24bd1961:God's spirit is like a Radio station, broadcasting all the time. You just have to learn how to tune in and receive his signal")); tweets.add(new Tweet("USER_136c16da","2010-03-07 19:56:54","RT @USER_11d35e61: @USER_136c16da finally a kindred spirit. *daps* lol thanks")); tweets.add(new Tweet("USER_47063e51","2010-03-04 12:47:54","cathartic - noun - a purification or purgation that brings about spiritual renewal or release from tension")); tweets.add(new Tweet("USER_1e4eb302","2010-03-03 20:13:18","Anything worth having you have to contribute yourself heart, mind, soul and spirit to. It is so rewarding. Have u contributed lately?")); tweets.add(new Tweet("USER_5d246e83","2010-03-04 14:57:01","@USER_8e090edb That's always good to hear. Starting off to a good morning, always puts your spirit in a great place.")); tweets.add(new Tweet("USER_b7117680","2010-03-03 06:55:17","I got a hustlas spirit, period!")); tweets.add(new Tweet("USER_25ecff25","2010-03-05 17:33:20","RT @USER_3a117437: The woman at the rental car spot tried 2 give us a Toyota! No ma'am lk the old spiritual says \"aint got time 2 die!\"")); tweets.add(new Tweet("USER_f91d8165","2010-03-03 22:33:24","#RandomThought why do people grab guns or knives when they think theres a ghost? DUMBASS! You can't shoot a spirit, grab some holy water! duh")); tweets.add(new Tweet("USER_86c542b8","2010-03-04 02:52:06","@USER_8cd1512d haha, maybe your right. I use to watch gymnastics all the time. I love the olympics. That's why I have so much spirit lol")); return tweets; } public static void main(String[] args) { ArrayList<Tweet> tweets = initTweetList(); MyHashTable<String,Tweet> tweetTable; int numBuckets = 7; // Initialize the hash table. Key will be the tweet dateAndTime. tweetTable = new MyHashTable<String,Tweet>(numBuckets); for (Tweet t: tweets) { tweetTable.put(t.getDateAndTime(), t); } System.out.println("New MyHashtable created....."); System.out.println("Number of tweets in the table: " + tweetTable.size()); System.out.println("Number of buckets in the table: " + tweetTable.numBuckets()); //System.out.println(tweetTable); System.out.println("\n---------------\nTesting get:\n---------------\n"); // Try to retrieve a tweet StringBuffer errors = new StringBuffer(); Tweet testTweet0 = tweetTable.get("2010-03-04 15:34:47"); System.out.println("testTweet0: \t" + testTweet0); if (testTweet0 == null || !testTweet0.getAuthor().equals("USER_989b85bb") || !testTweet0.getMessage().equals("I can be MADE into a need.")) { errors.append("Failed to retrieve tweet from '2010-03-04 15:34:47'.\n"); } System.out.println("\n---------------\nTesting rehash:\n---------------\n"); // rehashing changes the capacity of the table, but not the number of entries Integer oldBucketCount = tweetTable.numBuckets(); Integer oldSize = tweetTable.size(); tweetTable.rehash(); Integer newBucketCount = tweetTable.numBuckets(); if( 2*oldBucketCount != newBucketCount || oldSize != tweetTable.size()){ errors.append("New bucket count = " + newBucketCount + "\n" ); errors.append("Expected bucket count = " + 2*oldBucketCount + "\n"); errors.append("New size = " + tweetTable.size() + "\n" ); errors.append("Expected size = " + oldSize + "\n"); } // Try to retrieve a tweet Tweet testTweet1 = tweetTable.get("2010-03-04 15:34:47"); System.out.println("testTweet1: \t" + testTweet1); if (testTweet1 == null || !testTweet1.getAuthor().equals("USER_989b85bb") || !testTweet1.getMessage().equals("I can be MADE into a need.")) { errors.append("Failed to retrieve tweet from '2010-03-04 15:34:47'.\n"); } System.out.println("\n---------------\nTesting remove:\n---------------\n"); // Try to remove a tweet Tweet removedTweet = tweetTable.remove("2010-03-03 06:55:17"); Tweet retrievedTweet = tweetTable.get("2010-03-03 06:55:17"); System.out.println("removedTweet: \t" + removedTweet); System.out.println("retrivedTweet: \t" + retrievedTweet); if (removedTweet == null || !removedTweet.getAuthor().equals("USER_b7117680") || !removedTweet.getMessage().equals("I got a hustlas spirit, period!") || retrievedTweet != null) { errors.append("Failed to remove tweet from '2010-03-03 06:55:17'.\n"); } //***************** Twitter Basic Checks *****************// System.out.println("\n*********************\nTwitter Basic Checks"); ArrayList<String> stopWords = new ArrayList<String>(); Twitter t = new Twitter(initTweetList(), stopWords); System.out.println("\n---------------\nTesting latestTweetByAuthor:\n---------------\n"); Tweet tweetByAuthor = t.latestTweetByAuthor("USER_989b85bb"); if (tweetByAuthor == null || !tweetByAuthor.getAuthor().equals("USER_989b85bb") || !tweetByAuthor.getMessage().equals("I can be MADE into a need.") || !tweetByAuthor.getDateAndTime().equals("2010-03-04 15:34:47")) { errors.append("Failer to retrieve the latest tweet by USER_989b85bb\n"); } System.out.println("Latest tweet by USER_989b85bb :" + tweetByAuthor); System.out.println("\n---------------\nTesting tweetByDate:\n---------------\n"); ArrayList<Tweet> tweetsByDate = t.tweetsByDate("2010-03-03"); if(tweetsByDate.size() != 9){ errors.append("Failed to retrieve all 9 tweets posted on 2010-03-03\n"); } System.out.println(tweetsByDate.size() + " tweets posted on 2010-03-03 :"); tweetsByDate.forEach(tweet -> System.out.println("\t" + tweet)); // PUT MORE TESTS HERE. // Display the test results System.out.println("\n---------------\nTEST RESULTS:\n---------------\n"); if (errors.length() == 0) { errors.append("All tests passed successfully."); } System.out.println(errors.toString()); System.out.println(); } }

Starter_code/HashPair.java Starter_code/HashPair.java package FinalProject_Template; public class HashPair<K,V> {     private K key;     private V value;     /*      * Constructor      */     public HashPair(K key, V value) {         this.key = key;         this.value = value;     }          /**      * Returns key of this HashPair      */     public K getKey() {         return this.key;     }     /**      * Return Value of this HashPair      */     public V getValue() {         return this.value;     }          /**      * Set the value of this HashPair      */     public void setValue(V value) {         this.value = value;     } } Starter_code/MyHashTable.java Starter_code/MyHashTable.java package FinalProject_Template; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; public class MyHashTable<K,V> implements Iterable<HashPair<K,V>>{     // num of entries to the table     private int numEntries;     // num of buckets      private int numBuckets;     // load factor needed to check for rehashing      private static final double MAX_LOAD_FACTOR = 0.75;     // ArrayList of buckets. Each bucket is a LinkedList of HashPair     private ArrayList<LinkedList<HashPair<K,V>>> buckets;           // constructor     public MyHashTable(int initialCapacity) {         // ADD YOUR CODE BELOW THIS                  //ADD YOUR CODE ABOVE THIS     }          public int size() {         return this.numEntries;     }          public boolean isEmpty() {         return this.numEntries == 0;     }          public int numBuckets() {         return this.numBuckets;     }          /**      * Returns the buckets variable. Useful for testing  purposes.      */     public ArrayList<LinkedList< HashPair<K,V> > > getBuckets(){         return this.buckets;     }          /**      * Given a key, return the bucket position for the key.       */     public int hashFunction(K key) {         int hashValue = Math.abs(key.hashCode())%this.numBuckets;         return hashValue;     }          /**      * Takes a key and a value as input and adds the corresponding HashPair      * to this HashTable. Expected average run time  O(1)      */     public V put(K key, V value) {         //  ADD YOUR CODE BELOW HERE                  return null;                  //  ADD YOUR CODE ABOVE HERE     }               /**      * Get the value corresponding to key. Expected average runtime O(1)      */          public V get(K key) {         //ADD YOUR CODE BELOW HERE                  return null;                  //ADD YOUR CODE ABOVE HERE     }          /**      * Remove the HashPair corresponding to key . Expected average runtime O(1)       */     public V remove(K key) {         //ADD YOUR CODE BELOW HERE                  return null;                  //ADD YOUR CODE ABOVE HERE     }               /**       * Method to double the size of the hashtable if load factor increases      * beyond MAX_LOAD_FACTOR.      * Made public for ease of testing.      * Expected average runtime is O(m), where m is the number of buckets      */     public void rehash() {         //ADD YOUR CODE BELOW HERE                  //ADD YOUR CODE ABOVE HERE     }               /**      * Return a list of all the keys present in this hashtable.      * Expected average runtime is O(m), where m is the number of buckets      */          public ArrayList<K> keys() {         //ADD YOUR CODE BELOW HERE                  return null;                  //ADD YOUR CODE ABOVE HERE     }          /**      * Returns an ArrayList of unique values present in this hashtable.      * Expected average runtime is O(m) where m is the number of buckets      */     public ArrayList<V> values() {         //ADD CODE BELOW HERE                  return null;                  //ADD CODE ABOVE HERE     }               /**      * This method takes as input an object of type MyHashTable with values that       * are Comparable. It returns an ArrayList containing all the keys from the map,       * ordered in descending order based on the values they mapped to.       *       * The time complexity for this method is O(n^2), where n is the number       * of pairs in the map.       */     public static <K, V extends Comparable<V>> ArrayList<K> slowSort (MyHashTable<K, V> results) {         ArrayList<K> sortedResults = new ArrayList<>();         for (HashPair<K, V> entry : results) {             V element = entry.getValue();             K toAdd = entry.getKey();             int i = sortedResults.size() - 1;             V toCompare = null;             while (i >= 0) {                 toCompare = results.get(sortedResults.get(i));                 if (element.compareTo(toCompare) <= 0 )                     break;                 i--;             }             sortedResults.add(i+1, toAdd);         }         return sortedResults;     }               /**      * This method takes as input an object of type MyHashTable with values that       * are Comparable. It returns an ArrayList containing all the keys from the map,       * ordered in descending order based on the values they mapped to.      *       * The time complexity for this method is O(n*log(n)), where n is the number       * of pairs in the map.       */          public static <K, V extends Comparable<V>> ArrayList<K> fastSort(MyHashTable<K, V> results) {         //ADD CODE BELOW HERE                  return null;                  //ADD CODE ABOVE HERE     }                    @Override     public MyHashIterator iterator() {         return new MyHashIterator();     }             private class MyHashIterator implements Iterator<HashPair<K,V>> {         //ADD YOUR CODE BELOW HERE                  //ADD YOUR CODE ABOVE HERE                  /**          * Expected average runtime is O(m) where m is the number of buckets          */         private MyHashIterator() {             //ADD YOUR CODE BELOW HERE                          //ADD YOUR CODE ABOVE HERE         }                  @Override         /**          * Expected average runtime is O(1)          */         public boolean hasNext() {             //ADD YOUR CODE BELOW HERE                          return false;                          //ADD YOUR CODE ABOVE HERE         }                  @Override         /**          * Expected average runtime is O(1)          */         public HashPair<K,V> next() {             //ADD YOUR CODE BELOW HERE                          return null;                          //ADD YOUR CODE ABOVE HERE         }              } } Starter_code/Tweet.java Starter_code/Tweet.java package FinalProject_Template; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; public class Tweet implements Comparable<Tweet> {     private String author;     private String dateAndTime; // format of the string "yyyy-MM-dd HH:mm:ss"     private String message;          public Tweet(String a, String dAndT, String m) {         this.author = a;         this.dateAndTime = dAndT;         this.message = m;     }          public String getAuthor() {         return this.author;     }          public String getDateAndTime() {         return this.dateAndTime;     }               public String getMessage() {         return this.message;     }               public String toString() {         String[] info = {this.author, this.dateAndTime, this.message};         return String.join("\t", info);     }          public int compareTo(Tweet t) {         DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");         LocalDateTime dateTime1 = LocalDateTime.parse(this.dateAndTime, format);         LocalDateTime dateTime2 = LocalDateTime.parse(t.dateAndTime, format);                  int c = dateTime1.compareTo(dateTime2);         if (c == 0) {             return this.author.compareTo(t.author);         }                   return c;     } } Starter_code/Twitter.java Starter_code/Twitter.java package FinalProject_Template; import java.util.ArrayList; public class Twitter {          //ADD YOUR CODE BELOW HERE              //ADD CODE ABOVE HERE           // O(n+m) where n is the number of tweets, and m the number of stopWords     public Twitter(ArrayList<Tweet> tweets, ArrayList<String> stopWords) {         //ADD YOUR CODE BELOW HERE                          //ADD CODE ABOVE HERE      }               /**      * Add Tweet t to this Twitter      * O(1)      */     public void addTweet(Tweet t) {         //ADD CODE BELOW HERE         //ADD CODE ABOVE HERE      }          /**      * Search this Twitter for the latest Tweet of a given author.      * If there are no tweets from the given author, then the       * method returns null.       * O(1)        */     public Tweet latestTweetByAuthor(String author) {         //ADD CODE BELOW HERE         return null;                  //ADD CODE ABOVE HERE      }     /**      * Search this Twitter for Tweets by `date' and return an       * ArrayList of all such Tweets. If there are no tweets on       * the given date, then the method returns null.      * O(1)      */     public ArrayList<Tweet> tweetsByDate(String date) {         //ADD CODE BELOW HERE                  return null;                  //ADD CODE ABOVE HERE     }          /**      * Returns an ArrayList of words (that are not stop words!) that      * appear in the tweets. The words should be ordered from most       * frequent to least frequent by counting in how many tweet messages      * the words appear. Note that if a word appears more than once      * in the same tweet, it should be counted only once.       */     public ArrayList<String> trendingTopics() {         //ADD CODE BELOW HERE                  return null;                  //ADD CODE ABOVE HERE            }                    /**      * An helper method you can use to obtain an ArrayList of words from a       * String, separating them based on apostrophes and space characters.       * All character that are not letters from the English alphabet are ignored.       */     private static ArrayList<String> getWords(String msg) {         msg = msg.replace('\'', ' ');         String[] words = msg.split(" ");         ArrayList<String> wordsList = new ArrayList<String>(words.length);         for (int i=0; i<words.length; i++) {             String w = "";             for (int j=0; j< words[i].length(); j++) {                 char c = words[i].charAt(j);                 if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))                     w += c;                              }             wordsList.add(w);         }         return wordsList;     }      }

Related Questions

Similar orders to Computer science assignment about hash and heaps (data structure)
43
Views
0
Answers
PG2 – LAB 2: BLACKJACK OBJECTS
CONTENTS Overview........................................................................................................................................................................2 Part A - Classes......................................................
24
Views
0
Answers
Excel Project with Documentation
In a new sheet, create one-variable data tables for these food items. For each previously selected food item, create a two-variable data table that calculates the amounts of calories based on various portion sizes and the number of portions. I have att...
52
Views
0
Answers
Computer Vision - (Machine Learning, Artificial Intelligence field) assignment in python
Video processing, image processing, object detection, object tracking, background removel. It needs to be in PYTHON. Objective The goal of this project is to develop an automatic system for video analysis of footages for the game of curling. The system...
19
Views
0
Answers
Writing and understanding simple java program code
I need help writing a java program with an Eclipse IDE. Once written I need to identify, objects, lists, algorithms, set of instructions, anything that explains how the code is written, what it does, and how an end user will use it...