Question: Write the java code The following incomplete WordList class is intended as a collection class for holding a list of words. class WordList { private

Write the java code

The following incomplete WordList class is intended as a collection class for holding a list of words.

class WordList {

private static final int DEFAULTSIZE = 100;

private int maxWords;

private String[] list;

private int length;

}

Here the constant provides a default value to replace any request for an illegal array size, the array provides a place to store the words, maxWords will record the size of the array, and length will record how many words are currently stored in it.

(a) Write a constructer for WordList that accepts a parameter for the size of the array. The constructor will create an array for the words of the requested size, or of the default size if the size requested is not appropriate. It will also record the size of the array and set the current length appropriately.

(b) Write a method addWord to add a word to the array. This will accept a String reference and return a Boolean value indicating whether or not the word in the String was able to be added. It should update the state of the collection object as appropriate. Note that a String object is immutable and can be added safely to the collection without needing to be copied.

(c) Write a method findWord to find the first occurrence in the collection of a word beginning with a specified prefix. This method will accept a reference to a String object containing the prefix and return a String reference to the word found, or null if there is no matching word. The String class contains a startsWith instance method, which accepts a String argument and returns a boolean indicating whether the instance string starts with the argument string.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!