" on a line by itself. For example, consider the following input file: This is an example of an input file with four different paragraphs.
The second paragraph is the longest with three lines, so your method should return 3 when processing this file.
The third paragraph was empty. This one is just short.
The method should count the number of lines in each paragraph and report that information to System.out. For example, if the input above is stored in a Scanner called input and we make the following call: int max = analyzeParagraphs(input); It should produce the following output: 2-line paragraph 3-line paragraph 0-line paragraph 1-line paragraph It would assign max the value 3 because the method returns the maximum number of lines in any given paragraph. You must exactly reproduce the format of this output. You may assume that the input file has no blank lines, that it contains at least one paragraph, and that each paragraph is terminated by a line containing just "
". You may not construct any extra data structures to solve this problem. 6. Arrays, 10 points. Write a static method called hasAlternatingParity that returns whether or not an array of integers has alternating parity (true if it does, false otherwise). The parity of an integer is 0 for even numbers and 1 for odd numbers. To have alternating parity, a list would have to alternate between even and odd numbers, as in the following list: [3, 2, 19, 8, 43, 64, 1, 0, 3] If these values are stored in an array called data and we make this call: hasAlternatingParity(data) the method would return true. If the array instead stored these values: [2, 13, 4, 1, 0, 9, 2, 7, 4, 12, 3, 2] it would return false because there are two even numbers in a row (4, 12). By definition, an empty list or a list of one element has alternating parity. You may assume the values in the array are not negative. You may not construct any extra data structures to solve this problem. 7. ArrayList, 10 points. Write a static method called collapse that takes an ArrayList of integer values as a parameter and that replaces each successive pair of integers in the list with the sum of the pair. For example, if a variable called list stores this sequence of values: [7, 2, 8, 9, 4, 13, 7, 1, 9, 10] Then the following call: collapse(list); should leave the list with the following values: [9, 17, 17, 8, 19] The first pair from the original list is collapsed into 9 (7 + 2), the second pair is collapsed into 17 (8 + 9), the third pair is collapsed into 17 (4 + 13) and so on. If the list stores an odd number of elements, the final element is not collapsed. For example, if the list had been: [1, 2, 3, 4, 5] Then the call on collapse would produce the following list: [3, 7, 5] with the 5 at the end of the list unchanged. You may not construct any extra data structures to solve this problem. You must solve it by manipulating the ArrayList you are passed as a parameter. See the cheat sheet for a list of available ArrayList methods. 8. Critters, 15 points. Write a class called Counter that extends the Critter class. The constructor for the Counter class takes an integer indicating a maximum value to count up to. For example, you would pass the value 5 to the Counter constructor to indicate that the corresponding Counter object should count up to 5. Different Counter objects will have different maximum values. On each successive move, the Counter object should display with an increasing count relative to its maximum until it reaches the maximum and then it should start back at 1. If the maximum is 5, it will go through this cycle of values when toString is called: 1/5, 2/5, 3/5, 4/5, 5/5, 1/5, 2/5, 3/5, 4/5, 5/5, 1/5, ... It initially displays as "1/5", then after one move it becomes "2/5", etc., starting back at "1/5" after 5 moves. For a maximum of 3, the pattern is: 1/3, 2/3, 3/3, 1/3, 2/3, 3/3, 1/3, 2/3, 3/3 Counter objects should be blue. They should always infect if an enemy is in front. If there isn't an enemy to infect, they should hop if possible. If there is no enemy in front and they can't hop, they should turn left. As in assignment 9, all fields must be declared private and fields that need to be initialized to a non-default value must be set in a constructor. 9. Arrays, 15 points. Write a static method called combineSublists that takes as parameters two arrays of integers, a "from index" (inclusive), and a "to index" (exclusive), and that returns a new array containing the specified sublist from the first list followed by the specified sublist from the second list. For example, if arrays list1 and list2 store the following: list1 = [7, 15, 4, 3, 8, 2] list2 = [42, -3, 5, 12, 17, 6, 0] then the call combineSublists(list1, list2, 1, 5) should return this array: [15, 4, 3, 8, -3, 5, 12, 17] | | | | +--list1--+ +--list2--+ Notice that the new array has values from list1 from indexes 1 through 4 followed by values form list2 from indexes 1 through 4. The call combine(list1, list2, 5, 6) would return this array: [2, 6] It includes the value from index 5 of list1 followed by the value at index 5 from list2. If the start and stop indexes are equal, your method should return an empty array. You may assume that the method is not passed indexes that would be illegal for the two arrays passed as parameters. The method should not construct any extra data structures other than the array to be returned and it should not alter its two array parameters. 10. Programming, 10 points. Write a static method called removeZeros that takes an array of integers as a parameter and that moves any zeros in the array to the end of the array, otherwise preserving the order of the list. For example, if a variable called "list" stores the following values: [7, 2, 3, 0, 4, 6, 0, 0, 13, 0, 78, 0, 0, 19, 14] then the call: removeZeros(list); should rearrange the values in the array so that it stores the following: [7, 2, 3, 4, 6, 13, 78, 19, 14, 0, 0, 0, 0, 0, 0] Notice that the six zeros have been moved to the end of the array and the other values are in the same order as in the original list. You are not allowed to use an auxiliary data structure such as a temporary array or ArrayList to solve this problem and you are not allowed to call any methods of the Arrays class or the Collections class. 11. Art, 1 point (bonus). You've programmed lions, bears, giants, and huskies, but what kind of critter would your TA be? Give an artistic rendering of how you see your TA fitting into the unforgiving world of the critter simulation. You may either write a poem or draw a picture. If your answer below indicates at least 1 minute of effort, you will receive full credit, although your TA would probably appreciate it if you put in a little more effort.