# 7.10. Mixed Up Code Practice¶

Try to solve each of the following. Click the Check button to check each solution. You will be told if your solution is too short, has a block in the wrong order, or you are using the wrong block. Some of the problems have an extra block or two that aren’t needed in the correct solution. Try to solve these on your phone or other mobile device!

The following program segment should be a class that adds some Strings of conversational phrases to a List and then prints them out. But, the blocks have been mixed up and include one extra block that is not needed in a correct solution. Drag the needed code from the left to the right and put them in order with the correct indention so that the code would work correctly. Click the Check button to check your solution.

The following program segment should be a method that traverses through an ArrayList of Strings (the parameter) and print out the elements in reverse order – so {“cat”, “dog”, “mouse”} should print “mouse, dog, cat, “ as output. Assume the ArrayList “myList” has been instantiated and filled with Strings. But, the blocks have been mixed up and include two extra blocks that are not needed in a correct 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 following program segment should remove all the zeros from an ArrayList of Integers. Assume the ArrayList “listOfNums” has been instantiated and filled with Integers. But, the blocks have been mixed up and include two extra blocks that are not needed in a correct solution. Drag the blocks from the left and put them in the correct order on the right. Click the Check button to check your solution.

The following program segment is a method that should return the smallest int given an ArrayList of Integers (the parameter). But, the blocks have been mixed up and include one extra block that is not needed in a correct solution. Drag the blocks from the left and put them in the correct order on the right. Click the Check button to check your solution.

The following program segment is a method that should remove all the positive and negative odd values in an ArrayList of Integers (the parameter). But, the blocks have been mixed up and include one extra block that is not needed in a correct solution. Drag the blocks from the left and put them in the correct order on the right. Click the Check button to check your solution.

The following method should calculate the average from an ArrayList of Integers (the parameter). But, the blocks have been mixed up and include one extra block that is not needed in a correct solution. Drag the needed code from the left to the right and put them in order with the correct indention so that the code would work correctly. Click the Check button to check your solution.

The following program segment is a method that should find the largest value given an ArrayList of Integers (the parameter) and move it to the back of the list. But, the blocks have been mixed up and include two extra blocks that are not needed in a correct solution. Drag the blocks from the left and put them in the correct order on the right. Click the Check button to check your solution.

The following method should remove all the Strings that have length 3 or shorter from an ArrayList of Strings (the parameter) – so {“catch”, “dog”, “tree”, “me”} should return {“catch”, “tree”}. But, the blocks have been mixed up and include one extra block that is not needed in a correct solution. Drag the needed code from the left to the right and put them in order with the correct indention so that the code would work correctly. Click the Check button to check your solution.

The following program segment is a method that should take each String from an ArrayList of Strings (the parameter) and add it again to the list – so {“cat”, “ribbon”, “house”} should become {“cat”, “cat”, “ribbon”, “ribbon”, “house”, “house”}. But, the blocks have been mixed up and include two extra blocks that are not needed in a correct solution. Drag the blocks from the left and put them in the correct order on the right. Click the Check button to check your solution.

The following method should remove a specific Integer (specified in parameter) whenever it occurs in a given ArrayList of Integers (the parameter). But, the blocks have been mixed up and include three extra blocks that are not needed in a correct solution. Drag the needed code from the left to the right and put them in order with the correct indention so that the code would work correctly. Click the Check button to check your solution.