1
answer
0
watching
225
views
23 Mar 2018

8. Write a class called WordSet representing a set of String objects which can contain an arbitrary number of strings, limited only by the memory available to the Java Virtual Machine. A set is a collection of elements, however, unlike a list, a set cannot contain duplicate elements. Therefore, as its name implies, a WordSet object cannot contain duplicate Strings that is, if one attempts to da String to a Wordset, and the wordset already contains an element which is equal to this string, the attempt will fail and the state of the Wordset will not change. All String comparisons performed in the methods defined in the Wordset class are done in a Case SENSITIVE manner. Note that in the method descriptions below, the phrase "this Wordset" means "the Wordset on which the method in question is called." Your Wordset class MUST provide the following INSTANCE methods • A constructor, which takes no parameters and initializes the new Wordset ohject so that it contains no elements • A method called add(), which takes as its only parameter a string and returns a value of type boolean. If this Wordset already contains a string which is equal to the parameter string, or the parameter String is null, then the state of this Wordset does not change and the method return false; otherwise, the parameter String is added to this Wordset. and the method returns true. • A method called remove().which takes as its only parameter a string and returns a value of type boolean. If this wordSet contains a string which is equal to the parameter String this string is removed from the WordSet and the method returns true. On the other hand, if the string parameter is null or this Wordset does not contain a string which is equal to the parameter string, then the state of this wordset does not change, and the method return false. • A method called get.size(), which takes no parameters and returns the number of strings currently stored in this Wordset. This method MUST NOT change the state of this Wordset. • A method called isMember(). which takes as its only parameter a string and retumsa value of type boolean which is true if this wordset contains the parameter String false otherwise. If the parameter String is null, this method also return false. This method MUST NOT change the state of this wordset. • A method called computebirrerence().which takes as its only parameter a Wordset and returns a new Wordset representing the difference between this wordset and the parameter Wordset: in other words, the WordSet returned by this method contains all the strings that are in this wordset, but not in the parameter Wordset. If the parameter Wordset contains all the elements of this WordSet or this WordSet contains no elements, then this method returns a new Wordset containing no elements. Finally, if the parameter Wordset is null or contains ne strings, then this method returns a new wordset which contains all the elements of this wordset. This method MUST NOT change the state of this wordset or the parameter Wordset. • A method called tostring , which takes the parameters and turns a string which is the textual representation of this wordset. This textual representation consists of the concatena tion of the following clements - The String - The text representation of each clement in the WordSet; cach pair of adjacent clements is separated by the String", but this String MUST NOT appear before the first clement or after the last element - The String") The order in which the elements of this Wordset appear in the textual representation generated by the tostring() method does not matter. If the WordSet contains to Brings, then the textual representation returned by this method is ". Note that you MUST respect proper encapsulation practices that is, the attributes and methods of your class MUST be declared using the proper visibility modifier NINT Um an array list (of string) to keep track of the string stored in a wordt ob joot Is there a method defined in the Array loist class which determines whether in clementis already wored in an array ist, and which will do a case-sensitive comparison when liked on an Arraylint of strings? See the pages 24-26 of this examination for information about potentially useful methods defined by the ArrayList class WRITE YOUR Wordset CLASS IN THE SPACE BELOW:

For unlimited access to Homework Help, a Homework+ subscription is required.

Collen Von
Collen VonLv2
24 Mar 2018

Unlock all answers

Get 1 free homework help answer.
Already have an account? Log in

Related questions

Related Documents

Weekly leaderboard

Start filling in the gaps now
Log in