Unit 7 Write Code for Toggle CodeΒΆ

This is the write code problems associated with the mixed up code problems.

The following program should create a List called conversation, add in some elements("hello", "goodbye", "how are you", and "see you later"), and print out the elements with ", " after each. Fill in the code so that it adds the elements to conversation. The rest of the program is finished for you.

Fix the two errors in the printBackwards method so that it will correctly iterate through the parameter myList backwards and print each element.

Write code to define the removeZeros method. This method should take in an ArrayList of integers listOfNums and delete all of the zeros. For example, {3, 0, 5, 0} would change into {3, 5}.

Write code for the findSmallest method. This code segment should take in an ArrayList nums and return the smallest element present. For example, findSmallest called on {5, 3, 1, 6} should return 1.

Write code to flesh out the removeOdd method. This method should take in a parameter nums and delete every odd number from it. For example, {5, 3, 2, 1, 4} should become {2, 4}.

Fill out the average method. It should take in an ArrayList nums and calculate the arithmetic mean (the sum divided by the length). For example, average called on {5, 9, 6} should return 6.66666666667 as that is (5 + 9 + 6) / 3.

Create the moveLargest method. This should find the largest value in an ArrayList of Integers (the parameter) and move it to the back of the list.

Write code to finish the removeShort method. It should take an ArrayList words and remove all elements that are three characters long or shorter. For example, {"Dog", "Monkey", "Lion", "Cat"} would become {"Monkey", "Lion"}.

Write the method doubleList. This should take in an ArrayList words and insert a copy of each element such that {"cat", "ribbon", "house"} would become {"cat", "cat", "ribbon", "ribbon", "house", "house"}.

Write the method removeElement. This should take in an ArrayList nums and an integer toRemove and remove every instance of that integer from nums. E.g., if nums was {3, 6, 5, 3, 4}, it should become {6, 5, 4} after calling removeElement(nums, 3).

You have attempted of activities on this page