6. Complete method to return if the argument is found at least once in an array of Strings. If the exists true String string argument is not found, return (10pts) target false. String[] names = { "Li", "Devon", "Sandeep", "Chris", "Regan" }; assertTrue(af.exists("Li", names, 5)); assertTrue(af.exists("Sandeep", names, 5)); assertFalse(af.exists("NOT HERE", names, 5)); public boolean exists(String target, String[] a, int n) { 7. Complete method such that when given a non-empty array of ints, returns a new array containing the post4 post4 elements from the original array that come after the right most 4 in the original array argument. The array argument will always contain at least one 4. (14pts) assertArrayEquals(new int[] {1, 2}, post4(new int[]{2, 4, 1, 2})); assertArrayEquals(new int[] {2}, post4(new int[]{4, 1, 4, 2})); assertArrayEquals(new int[] {1, 2, 3}, post4(new int[]{4, 4, 1, 2, 3})); assertArrayEquals(new int[] {}, post4(new int[]{4})); // Precondition: The array argument is never an empty array and always contains at least one 4 public int[] post4(int[] nums) {
6. Complete method exists to return true if the String argument is found at least once in an array of Strings. If the string argument target is not found, return false. (10pts) String[] names = { "Li", "Devon", "Sandeep", "Chris", "Regan" }; assertTrue(af.exists("Li", names, 5)); assertTrue(af.exists("Sandeep", names, 5)); assertFalse(af.exists("NOT HERE", names, 5)); public boolean exists(String target, String[] a, int n) { 7. Complete method post4 such that when given a non-empty array of ints, post4 returns a new array containing the elements from the original array that come after the right most 4 in the original array argument. The array argument will always contain at least one 4. (14pts) assertArrayEquals(new int[] {1, 2}, post4(new int[]{2, 4, 1, 2})); assertArrayEquals(new int[] {2}, post4(new int[]{4, 1, 4, 2})); assertArrayEquals(new int[] {1, 2, 3}, post4(new int[]{4, 4, 1, 2, 3})); assertArrayEquals(new int[] {}, post4(new int[]{4})); // Precondition: The array argument is never an empty array and always contains at least one 4 public int[] post4(int[] nums) {
227PracticeMidTermSum15.docx