Part a. A RandomStringChooser object is constructed from an array of non-null String values. When the object is first constructed, all of the strings are considered available. The RandomStringChooser class has a getNext method, which has the following behavior. A call to getNext returns a randomly chosen string from the available strings in the object. Once a particular string has been returned from a call to getNext, it is no longer available to be returned from subsequent calls to getNext. If no strings are available to be returned, getNext returns "NONE.
The mixed up code below includes the correct code for the class, a field, a constructor, and the getNext method. In the constructor it will create an ArrayList and fill it by looping through the array and adding each string to the list. In the getNext method, if the list length is greater than zero, it will pick a position at random in the list and remove the item from that position and return it. Otherwise, if the list is empty, it returns βNONEβ. The blocks have been mixed up and include extra blocks that arenβt needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the Check button to check your solution.
The mixed up code below includes the correct code for the class, an instance variable, a constructor, and the getNext method. In the constructor it will create an ArrayList and fill it by looping through the array and adding each string to the list. In getNext it will return βNONEβ if the length of the list is 0. Otherwise, it will calculate a random index in the list, remove the string at that index, and return it. The blocks have been mixed up and include extra blocks that arenβt needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the Check button to check your solution.