Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hi, I got task 1 done. need help with how to proceed with task 2. to write the new Class Dictionry. Check below for two
Hi, I got task 1 done. need help with how to proceed with task 2. to write the new Class Dictionry. Check below for two pictures. one of Task 2 and the already written Class Word.
[" The Task 2"]
["Class Word"]
3 Task 2: The class Dictionary The instance variables of this class are theList and backup. You initialize backup to null when you declare it. theList is initialized in the constructor. addString(arg) takes in the string ary. If ary is not yet contained in any element of theList, then addString(arg) creates a new instance of Word with a value count =1 and adds it to theList. If there is already an instance of Word with a value of theWord equal to arg, then it increases its value of count by 1. Use only the methods listed in the class diagram of Word (don't implement a method that changes count). addString(String) should return the return value of toString() of the added or updated instance of Word. sortList(arg) sorts the instances of Word in theList according to the value of ary. If sortList(arg) is called for the first time, then it should attach a deep copy of theList to backup. If arg of sortList(arg) has the value of the class constant ORIGINAL, then it should (shallow) copy the address of backup to theList, set the value of sortCriterion to that of ORIGINAL, and return "Word list was reset". If arg has the value of one of the other class constants, then you set sortCriterion to arg and you start off with a loop over all elements of theList. Use the method compareTo(arg) of Word to compare the instance of Word at the current position in theList to the instances in the slots with a higher index. If the result of compareTo(arg) is 1, you swap both instances of Word. In the end, you get a list that is either sorted by the number of count or alphabetically by the value of the Word. The elements of theList will be sorted in descending order. sortList(arg) should return "Sorted by counts" or "Sorted alphabetically" depending on the value of sortCriterion. 2 return Word(arg) checks if theList has an instance of Word at the slot with the index ary. If ary exceeds the largest index of theList, the method should return "end". Otherwise, it should return the return value of toString() of that instance of Word. toString() should return a string that starts with "Content: " followed by a line break. It should call the toString() methods of all elements of theList and concatenate their return strings to one large string. There should be a line break between each. The method should return the concatenated stringStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started