" 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 isAllPairs that takes an array of integers as a parameter and that returns whether or not the array is made up entirely of pairs of the same value. For example, if a variable called "list" stores the following values: {3, 3, 4, 4, 5, 5, 6, 6, 7, 7} | | | | | | | | | | +--+ +--+ +--+ +--+ +--+ pair pair pair pair pair then the following call: isAllPairs(list) should return true because the array is entirely made up of pairs of the same value: the first two values are both 3, the second two values are both 4 and so on. Your method should return false if passed an array with an odd number of values. You may assume that the array contains at least one value. Below are several sample calls. Contents of Array Value Returned ------------------------------------------------------------ {1} false {1, 1} true {1, 1, 2, 2, 3, 3} true {2, 2, 55, 55, 33, 33, 33, 33}; true {2, 2, 5, 5, 6, 7, 3, 4} false {3, 3, 2, 4, 4}; false {2, 2, 1, 1, 1}; false 7. ArrayList, 10 points. Write a static method called split that takes an ArrayList of integer values as a parameter and that replaces each value in the list with a pair of values, each half the original. If a number in the original list is odd, then the first number in the new pair should be one higher than the second so that the sum equals the original number. For example, if a variable called list stores this sequence of values: [18, 7, 4, 24, 11] The number 18 is split into the pair (9, 9), the number 7 is split into (4, 3), the number 4 is split into (2, 2), the number 24 is split into (12, 12) and the number 11 is split into (6, 5). Thus, the call: split(list); should cause list to store the following sequence of values afterwards: [9, 9, 4, 3, 2, 2, 12, 12, 6, 5] You may assume that all numbers in the list are nonnegative. 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 Sponge that extends the Critter class. The instances of the Sponge class infect if an enemy is front of them, hop if there is an empty space in front of them, and otherwise turn left or right. They display themselves as square brackets with one or more dashes inside, as in "[-]" or "[----]". They are always colored yellow. They should always display at least one dash and should initially display one dash. Each time a Sponge infects, it increases the number of dashes in the display by one and each time a Sponge turns it decreases the number of dashes in the display by one unless it has gotten down to a single dash. In deciding which direction to turn, each Sponge should follow a pattern that repeats every three turns. The first turn should be left and the second and third turns should be right. Then it repeats with another left turn followed by two right turns, and so on. As in assignment 8, fields must be declared private, fields initialized to a non-default value must be set in a constructor, and all updates to fields must occur in the getMove method. 9. Arrays, 15 points. Write a static method called surroundWithN that takes two arrays of integers and an integer n as parameters and that returns a new array that contains the result of adding the first n values from the second array at both the front and the back of the first array. For example if the variables list1 and list2 contain the following values: list1: [2, 8, 17, 3, 9, 0] list2: [103, 72, -8, 15, 42] The call surroundWithN(list1, list2, 3) should return a new array storing: [103, 72, -8, 2, 8, 17, 3, 9, 0, 103, 72, -8] | | | | | | +--------+ +---------------+ +--------+ from list2 list1 from list2 Notice that the new array has the first three values from list2 followed by the values from list1 followed by the first three values from list2. You may assume that the value n passed as a parameter is legal (between 0 and the length of the second array). Your method should not construct any extra data structures other than the array to be returned and it should not alter its two array parameters. You are not allowed to call methods of the Arrays class to solve this problem. 10. Programming, 10 points. Write a static method called acronym that takes as a parameter a string containing a phrase and that returns a string that has the acronym for the phrase. For example, the following call: acronym("self-contained underwater breathing apparatus") should return "SCUBA". The acronym is formed by combining the capitalized first letters of each word in the phrase. Words in the phrase will be separated by some combination of dashes and spaces. There might be extra spaces or dashes at the beginning or end of the phrase. The string passed as a parameter will not contain any characters other than dashes, spaces, and letters, and is guaranteed to contain at least one word. Below are several sample calls. Method Call Value Returned ----------------------------------------------- -------------- acronym(" automatic teller machine ") "ATM" acronym("personal identification number") "PIN" acronym("computer science") "CS" acronym("merry-go-round") "MGR" acronym("All my Children") "AMC" acronym("Troubled Assets Relief Program") "TARP" acronym("--quite-- confusing - punctuation-") "QCP" acronym(" loner ") "L" You are allowed to construct extra data structures to solve this problem (an array, ArrayList, Scanner, String, etc), but you may use only methods listed on the cheat sheet.