A concordance is an alphabetical index of the principal words in a context. This assignment will create a concordance for a chapter of Alice in Wonderland.
The assignment specifies many of the required methods, but you can and should add more of your own design.
PART 1: THE WORDDATA CLASS
Create a WordData class which will store all the information about one particular word in the concordance,including:
• The word itself (a String of lowercase letters only)
• A list of all of the line numbers on which the word appears. This must be stored as an ArrayList<Integer> object.
• The number of times the word appears. This may be different from the length of the ArrayList because a word might appear more than once on the same line.
Provide a suitable constructor and other methods to create and manage these objects. You must have:
• A standard toString method that will show the word, its frequency, and the lines on which it appears. If there is a large list of lines, show only the first 15 of them, followed by … and then the last one. For example:
alice appears 386 times on 384 lines:
• A standard equals method boolean equals(Object other) which will return true if the other Object is a WordData object that contains the same word. The frequency and list of lines are ignored while making the comparison. Note that the parameter must be type Object and not type WordData (this is required so that the method will override the equals method in the Object class).
• A standard compareTo method int compareTo(Object other) which will compare the frequencies of two WordData objects (the word itself and the list of lines are ignored). It should return a negative value if this word has a larger frequency than the other word, a 0 if they are the same, and a positive number otherwise. (This will be used to sort frequencies into descending order, so the output is the reverse of the normal output.) If the other Object is not a WordData object at all, return 0.
PART 2: THE WORDDATAARRAYLIST CLASS
The concordance will consist of a list of WordData objects, so create a class to hold such a list. An ArrayList<WordData> would do almost what we need, but not quite. The standard add methods for the ArrayList class don’t work the correct way, and so we will need to implement a special one.
• Create a WordDataArrayList class which is a subclass of ArrayList<WordData>. This means that a WordDataArrayList object will not contain an ArrayList instance variable. It will be an ArrayList itself. Think about how we talked about “has a” and “is a” relationship.
• Provide a method void add(int line, String word) which indicates that the given word has appeared on the given line. The list should be adjusted accordingly. If a WordData object for that word already exists, it should be modified considering the frequency of the word, otherwise a new one should be created.
• Pay attention that this class is a subclass of ArrayList<WordData>. You can use arrayList methods in this class even without creating a new arrayList object.
Run your own tests on this class before continuing.
本网站支持淘宝 支付宝 微信支付 paypal等等交易。如果不放心可以用淘宝交易！
E-mail: firstname.lastname@example.org 微信:itcsdx