Question: Exercise II ArrayLists Create a class called OurArrayList and implement the following methods: 1- Write a method called scaleByK() that takes an ArrayList of integers

 Exercise II ArrayLists Create a class called OurArrayList and implement thefollowing methods: 1- Write a method called scaleByK() that takes an ArrayList

Exercise II ArrayLists Create a class called OurArrayList and implement the following methods: 1- Write a method called scaleByK() that takes an ArrayList of integers as a parameter and replaces every integer of value K with K copies of itself. For example, if the list stores the values (4, 1, 2,0,3) before the method is called, it should store the values (4,4,4,4, 1, 2, 2, 3, 3, 3) after the method finishes executing. Zeroes and negative numbers should be removed from the list by this method. 2- Write a method called removeDuplicates() that takes as a parameter a sorted ArrayList of Strings and eliminates any duplicates from the list. For example, if the list stores the values (be, be, is, not, or, question, that, the, to, to) before the method is called, it should store the values (be, is, not, or, question, that, "the", "to") after the method finishes executing. Because the values will be sorted, all of the duplicated will be grouped together. Assume that the ArrayList contains only string values, but keep in mind that it might be empty. 3- Write a method called removeInRange() that accepts three parameters, an ArrayList of Strings, a beginning String, and an ending String, and removes from the list any Strings that fall alphabetically between the start and end Strings inclusive. For example, if the method is passed a list containing the elements("to, be, or, "not", "to", be, that, "s", "the", "question"), "free" as the start String, and rich" as the end String, the list's elements should be changed to ("to", "be", "40", "be", "that", "the"). The "or", "not", "s, and question should be removed because they occur alphabetically between "free" and "rich. And if the method is passed the same list with "be" as a starting string and "right" as the end String, the list's elements should be changed to ("to", "to", "that, "the"). You may assume that the start String alphabetically precedes the ending String. 4- Write a method markLength40 that takes an ArrayList of Strings as a parameter and that places a String of four asterisks ("****") in front of every String of length 4. For example, suppose that an ArrayList called "list" contains the following values: (this, is, lots, of, fun, for, every, Java, programmer) And you make the following call: markLength4(list); Then list should store the following values after the call: (****, this, is, ****, lots, of, fun, for, every, ****, Java, programmer) Notice that you leave the original Strings in the list (this, lots. Java) but include the four- asterisk String in front of each to mark it. You may assume that the ArrayList contains only String values, but it might be empty. Include a main method and test all your methods with appropriate examples. Exercise II ArrayLists Create a class called OurArrayList and implement the following methods: 1- Write a method called scaleByK() that takes an ArrayList of integers as a parameter and replaces every integer of value K with K copies of itself. For example, if the list stores the values (4, 1, 2,0,3) before the method is called, it should store the values (4,4,4,4, 1, 2, 2, 3, 3, 3) after the method finishes executing. Zeroes and negative numbers should be removed from the list by this method. 2- Write a method called removeDuplicates() that takes as a parameter a sorted ArrayList of Strings and eliminates any duplicates from the list. For example, if the list stores the values (be, be, is, not, or, question, that, the, to, to) before the method is called, it should store the values (be, is, not, or, question, that, "the", "to") after the method finishes executing. Because the values will be sorted, all of the duplicated will be grouped together. Assume that the ArrayList contains only string values, but keep in mind that it might be empty. 3- Write a method called removeInRange() that accepts three parameters, an ArrayList of Strings, a beginning String, and an ending String, and removes from the list any Strings that fall alphabetically between the start and end Strings inclusive. For example, if the method is passed a list containing the elements("to, be, or, "not", "to", be, that, "s", "the", "question"), "free" as the start String, and rich" as the end String, the list's elements should be changed to ("to", "be", "40", "be", "that", "the"). The "or", "not", "s, and question should be removed because they occur alphabetically between "free" and "rich. And if the method is passed the same list with "be" as a starting string and "right" as the end String, the list's elements should be changed to ("to", "to", "that, "the"). You may assume that the start String alphabetically precedes the ending String. 4- Write a method markLength40 that takes an ArrayList of Strings as a parameter and that places a String of four asterisks ("****") in front of every String of length 4. For example, suppose that an ArrayList called "list" contains the following values: (this, is, lots, of, fun, for, every, Java, programmer) And you make the following call: markLength4(list); Then list should store the following values after the call: (****, this, is, ****, lots, of, fun, for, every, ****, Java, programmer) Notice that you leave the original Strings in the list (this, lots. Java) but include the four- asterisk String in front of each to mark it. You may assume that the ArrayList contains only String values, but it might be empty. Include a main method and test all your methods with appropriate examples

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!