Question: Please help me to solve this source code import java.util.ArrayList; import java.util.Arrays; /** * ArrayList Problems * * @author * @version */ public class PS13
Please help me to solve this source code
import java.util.ArrayList; import java.util.Arrays; /** * ArrayList Problems * * @author * @version */ public class PS13 { /** * Write the method named mesh. * * Start with two ArrayLists of String, A and B, each with * its elements in alphabetical order and without any duplicates. * Return a new list containing the first N elements from the two * lists. The result list should be in alphabetical order and without * duplicates. A and B will both have a size which is N or more. * Your solution should make a single pass over A and B, taking * advantage of the fact that they are in alphabetical order, * copying elements directly to the new list. * * Remember, to see if one String is "greater than" or "less than" * another, you need to use the compareTo() method, not the < or > * operators. * * Examples: * mesh(["a","c","z"], ["b","f","z"], 3) returns ["a","b","c"] * mesh(["a","c","z"], ["c","f","z"], 3) returns ["a","c","f"] * mesh(["f","g","z"], ["c","f","g"], 3) returns ["c","f","g"] * * @param a an ArrayList of String in alphabetical order. * @param b an ArrayList of String in alphabetical order. * @param n the size of the resulting list to return. * @return a list of n elements in alphabetical order. */ // TODO - Write the mesh method here.
/** * Write the method named examScore(). * * The "key" list contains the correct answers * to an exam, like ["a", "a", "b", "b"]. The "answers" * list contains a student's answers, with "?" representing * a question left blank. The two lists are not empty and * are the same length. Return the score for this list * of answers, giving +4 for each correct answer, -1 for * each incorrect answer, and +0 for each blank answer. * * Examples: * examScore(["a", "a", "b", "b"], ["a", "c", "b", "c"]) returns 6 * examScore(["a", "a", "b", "b"], ["a", "a", "b", "c"]) returns 11 * examScore(["a", "a", "b", "b"], ["a", "a", "b", "b"]) returns 16 * * @param key a list of correct answers to an exam. * @param answers the student's answers to the exam. * @return the score as described above. */ // TODO - Write the examScore method here.
/** * Write the method filterBySize(). * * Given an ArrayList of String, return a new list where only * strings of the given length are retained. * * Examples: * filterBySize(["a", "bb", "b", "ccc"], 1) returns ["a", "b"] * filterBySize(["a", "bb", "b", "ccc"], 3) returns ["ccc"] * filterBySize(["a", "bb", "b", "ccc"], 4) returns [] * * @param list the list of Strings to process. * @param n the size of words to retain. * @return a new list of words with the indicated size retained. */ // TODO - Write the filterBySize method here. /** * Write the method named nOdds(). * * Given an ArrayList of positive Integers, return a new list * of length "count" containing the first odd numbers from * the original list. The original will contain at least * "count" odd numbers. * * Examples: * nOdds([3, 2, 4, 5, 8], 2) returns [3, 5] * nOdds([3, 2, 4, 5, 8, 9], 3) returns [3, 5, 9] * nOdds([3, 1, 2, 4, 5, 8], 3) returns [3, 1, 5] * * @param list the ArrayList of Integers to search. * @param count the number of odd numbers to copy. * @return the first "count" odd numbers from the list. */ // TODO - Write the nOdds method here.
// A utility method for testing @SuppressWarnings("unchecked") public static
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
