Question 1 (30 points) Write a search method search (.....) with four parameters: the search array, the target, the start subscript, and the finish subscript. The last two parameters indicate the part of the array that should be searched. If the target is found, the method returns the index of the first occurrence of the target in the array. If the target is not found, the method returns -1. Your method should catch or throw exceptions where warranted. Question 2 (30 points) Listing 3.1 of your textbook (pages 130-131) shows a JUnit test harness for an array search method (ArraySearch.search) that returns the location of the first occurrence of a target value (the second parameter) in an array (the first parameter) or −1 if the target is not found. Modify the test(s) in the listing to verify a method that finds the last occurrence of a target element in an array.
Question 3 (40 points) Consider the method findLargest () defined as follows: /** * Search an array to find the first occurrence of the * largest element * @param x Array to search * @return The subscript of the first occurrence of the * largest element * @throws NullPointerException if x is null */ public static int findLargest (int[] x) {...} Write the JUnit test harness for the method findLargest().
Question 1 (30 points) Write a search method search (.....) with four parameters: the search array, the target, the star
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am