Need Help
Using Java programming only
import java.util.ArrayList;
//Import anything you need here
public class Dictionary {
// Declare any variables you feel necessary
here
public Dictionary(/*DO NOT PUT ANY PARAMETERS
HERE!*/) {
// Initialise those
variables
}
/***
* @return number of terms currently in the
dictionary hint: starts at 0 when
* there are no
terms
*/
public int numberOfTerms() {
return 0;
}
/***
* Add a Term to your dictionary, given a
word and a definition, store them for
* later use in your dictionary
*
* @param word word portion of Term
* @param definition definition portion of
Term
*
*/
public void addTerm(String word, String
definition) {
}
/**
* Implement functionality to retrieve a
random term from your dictionary. This
* could be used for a word of the day on a
website.
*
* @return the random term
*/
public Term getRandomTerm() {
return null;
}
/**
* Given a partial search string, check if
any of the words you have stored match the given search
string.
*
* If your dictionary contained Terms:
apple, pineapple, paper, master.
*
* If search contained "ap" the results
should be an ArrayList containing: apple, pineapple, paper.
*
* @param search string
* @return An ArrayList of Strings
containing the results
*/
public ArrayList<String>
searchForWord(String search) {
return null;
}
/**
* Given a partial search string, check if
any of the words you have stored start with a given
character.
* 'p'
* If your dictionary contained Terms:
apple, pineapple, paper, master.
*
* If c contained 'p' the results should be
an ArrayList containing: pineapple, paper.
*
* @param c character that begins
words
* @return An ArrayList of Strings
containing the results
*/
public ArrayList<String>
searchForWordStartsWith(char c) {
return null;
}
}
Thanks for the question, for the problem you need to implement one more class called Term.java. as the method getRandomTerm () returns and object of Term.java class.
Here are the Term.java class and also the implemented methods of the Dictionary.java, we have used HashMap ADT to store the words and their corresponding meaning. Words will form the key while the meaning will be the value.
Let me know for any changes or for any further help. Thank You !
==============================================================================================
public class Term {
private String
word;
private String
definition;
public Term(String word, String
definition) {
this.word = word;
this.definition =
definition;
}
public String getWord() {
return
word;
}
public String getDefinition()
{
return
definition;
}
public void setWord(String
word) {
this.word = word;
}
public void
setDefinition(String definition) {
this.definition =
definition;
}
}
==========================================================================================
import java.util.*; import java.util.ArrayList; //Import anything you need here public class Dictionary { // Declare any variables you feel necessary here private HashMap<String, String> map; public Dictionary(/*DO NOT PUT ANY PARAMETERS HERE!*/) { // Initialise those variables map = new HashMap<>(); } /*** * @return number of terms currently in the dictionary hint: starts at 0 when * there are no terms */ public int numberOfTerms() { return map.size(); } /*** * Add a Term to your dictionary, given a word and a definition, store them for * later use in your dictionary * * @param word word portion of Term * @param definition definition portion of Term * */ public void addTerm(String word, String definition) { map.put(word, definition); System.out.println("Added to dictionary successfully."); } /** * Implement functionality to retrieve a random term from your dictionary. This * could be used for a word of the day on a website. * * @return the random term */ public Term getRandomTerm() { Random random = new Random(); int randNumber = random.nextInt(map.size()); int i = 0; for (Map.Entry<String, String> iter : map.entrySet()) { if (i++ == randNumber - 1) { return new Term(iter.getKey(), iter.getValue()); } } return null; } /** * Given a partial search string, check if any of the words you have stored match the given search string. * <p> * If your dictionary contained Terms: apple, pineapple, paper, master. * <p> * If search contained "ap" the results should be an ArrayList containing: apple, pineapple, paper. * * @param search string * @return An ArrayList of Strings containing the results */ public ArrayList<String> searchForWord(String search) { ArrayList<String> matches = new ArrayList<>(); for (String key : map.keySet()) { if (key.contains(search)) { matches.add(key); } } return matches; } /** * Given a partial search string, check if any of the words you have stored start with a given character. * 'p' * If your dictionary contained Terms: apple, pineapple, paper, master. * <p> * If c contained 'p' the results should be an ArrayList containing: pineapple, paper. * * @param c character that begins words * @return An ArrayList of Strings containing the results */ public ArrayList<String> searchForWordStartsWith(char c) { ArrayList<String> matches = new ArrayList<>(); for (String key : map.keySet()) { if (key.length() > 0 && key.charAt(0) == c) { matches.add(key); } } return matches; } }
Need Help Using Java programming only import java.util.ArrayList; //Import anything you need here public class Dictionary...
complete this in java import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class WordDetective { /** * Picks the first unguessed word to show. * Updates the guessed array indicating the selected word is shown. * * @param wordSet The set of words. * @param guessed Whether a word has been guessed. * @return The word to show or null if all have been guessed. */ public static String pickWordToShow(ArrayList<String> wordSet, boolean []guessed) { return null; //TODO...
JAVA programming 9.9 Ch 9, Part 2: ArrayList Searching import java.util.ArrayList; public class ArrayListSet { /** * Searches through the ArrayList arr, from the first index to the last, returning an ArrayList * containing all the indexes of Strings in arr that match String s. For this method, two Strings, * p and q, match when p.equals(q) returns true or if both of the compared references are null. * * @param s The string...
complete this in java import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class WordDetective { /** * Picks the first unguessed word to show. * Updates the guessed array indicating the selected word is shown. * * @param wordSet The set of words. * @param guessed Whether a word has been guessed. * @return The word to show or null if all have been guessed. */ public static String pickWordToShow(ArrayList<String> wordSet, boolean []guessed) { return null;...
complete this in java import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class WordDetective { /** * Finds the specified set of words in the specified file and returns them * as an ArrayList. This finds the specified set in the file which is on the * line number of the set. The first line and set in the file is 1. * * This returns an ArrayList with the keyword first, then : and then followed...
Please help with Java array list: import java.util.ArrayList; public class ListUpdate { /** * Does a linear search through the ArrayList list, returning the index of the first occurrence of * valToFind. * * Starting from index 0, check each element in list and return the index of the first element * that matches valToFind. * * @param valToFind The int value to search for. * @param list The ArrayList of Integers to search in. * @return The index of...
/** * */ package groceries; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class ShoppingList { /** * @param args */ public static void main(String[] args) { List groceryList = new ArrayList<>(); groceryList.add("rice"); groceryList.add("chicken"); groceryList.add("cumin"); groceryList.add("tomato"); groceryList.add("cilantro"); groceryList.add("lime juice"); groceryList.add("peppers"); groceryList.remove("cilantro"); for (int i = 0; i if (groceryList.get(i).equals("peppers")) {...
PLEASE COMPLETE THE CODES. package javaprogram; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; /** * Movie class definition. * * @author David Brown * @version 2019-01-22 */ public class Movie implements Comparable { // Constants public static final int FIRST_YEAR = 1888; public static final String[] GENRES = { "science fiction", "fantasy", "drama", "romance", "comedy", "zombie", "action", "historical", "horror", "war" }; public static final int MAX_RATING = 10; public static final int MIN_RATING = 0; /** * Converts a string of...
Complete code and answer question in comments: Package hw4; import java.util.ArrayList; public class WordGame { /* * Returns all strings that appear * as a consecutive horizontal or vertical sequence of letters * (left-right, right-left, up-down, or down-up) * in the array board and also appear in dict. * Note that the same word may appear multiple times * on the board, and will then be multiple times in * the returned array. * * dict is assumed to be...
Need help coding this List. Lists are a lot like arrays, but you’ll be using get, set, add, size and the like instead of the array index operators []. package list.exercises; import java.util.List; public class ListExercises { /** * Counts the number of characters in total across all strings in the supplied list; * in other words, the sum of the lengths of the all the strings. * @param l a non-null list of strings ...
Implement the missing methods in java! Thanks! import java.util.Iterator; import java.util.NoSuchElementException; public class HashTableOpenAddressing<K, V> implements DictionaryInterface<K, V> { private int numEntries; private static final int DEFAULT_CAPACITY = 5; private static final int MAX_CAPACITY = 10000; private TableEntry<K, V>[] table; private double loadFactor; private static final double DEFAULT_LOAD_FACTOR = 0.75; public HashTableOpenAddressing() { this(DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR); } public HashTableOpenAddressing(int initialCapacity, double loadFactorIn) { numEntries = 0; if (loadFactorIn <= 0 || initialCapacity <= 0) { throw new IllegalArgumentException("Initial capacity and load...