Question: 0. Include the following declaration at the beginning of your class, immediately after the class header: public static final String[] COLLEGES { CAS CFA, CGS,

![immediately after the class header: public static final String[] COLLEGES { "CAS"](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f3ad13c7232_58766f3ad1331e03.jpg)




0. Include the following declaration at the beginning of your class, immediately after the class header: public static final String[] COLLEGES { "CAS" "CFA", "CGS", "COM", "ENG", "QST", "SAR", "SED", "SHA", "OTHER" }; It declares a variable called COLLEGES that refers to an array of strings that you will use in one of your methods. The syntax that we are using to declare this variable makes it a class constant. Declaring a variable to be static means it has class-level scope and can be accessed by any method written in the class. Declaring a variable to be final means that it is a constant that cannot be modified by code elsewhere in the program. By convention, when declaring a class constant, we capitalize the entire variable name. Doing so makes it easier for readers of our code to recognize that the variable is a constant, and to know that they can find its value at the top of the class. 1. Write a method with the header public static int getCollegeNum(String coll) that takes a reference to a string and returns the index of that string in the array referred to by the class constant COLLEGES that you declared above. For example: 1 getCollegeNum("CAS") should return 0, because "CAS" has an index of 0 in the COLLEGES array. getDayIndex("QST") should return 5, because "QST" has an index of 5 in the COLLEGES array. 1 Important notes: . If the parameter is null or the string is not found in the array, the method should return -1. Your method should work even if we change the contents of the COLLEGES array. In other words, you should write code that processes an arbitrary array of String objects called COLLEGES. You should not make any assumptions about the contents of the array. 2. Write a method with the header public static void negateEvens(int[] arr) that takes a reference to an array of integers and negates (i.e., multiplies by -1) all of the even numbers in the array. For example, if you add the following test code to your main method: int[] al = {1, 2, 4, 5, -8, -10, -11}; negateEvens(al); System.out.println(Arrays.toString(a1)); you should see the following output: [1, -2, -4, 5, 8, 10, -11] Special case: If the parameter is null, the method should throw an IllegalArgumentException. 3. Write a method with the header public static int[] slice(int[] values, int start, int end) that takes a reference to an array of integers values and two integers start and end, and that creates and returns a new array that contains the elements in the "slice/subarray ofvalues that begins at position start and goes up to but not including position end. For example: int[] a2 = {2, 5, 6, 3, 7, 4, 1}; int[] a3 = ArrayMethods.slice(a2, 2, 5); System.out.println(Arrays.toString(a3)); should display: [6, 3, 7] Important: You may not use any of the built-in methods for copying or extracting a portion of an array. You must not modify the original array. Special cases: If the first parameter is null, the method should throw an IllegalArgumentException. If start or end are invalid (i.e., less than 0 or greater than the length of the array), the method should throw an ArrayIndexOutOfBoundsException. . If start and end are valid indices but end is less than or equal to start, the method should return an array of length 0. For example, given the array a2 defined above: int[] a4 = ArrayMethods.slice(a2, 5, 2); System.out.println(Arrays.toString(a4)); should display: 4. Write a method with the header public static boolean isSorted(int[] arr) that takes a reference to an array of integers and returns true if the array is sorted and false otherwise. For example: int[] a5 {2, 5, 6, 6, 9, 9, 9, 10}; int[] a6 = {2, 5, 6, 4, 9, 9, 7, 10}; System.out.println(ArrayMethods. isSorted(a5)); System.out.println(ArrayMethods.isSorted(26)); should display: should display: true false Special cases: If the method is passed a value of null, it should throw an IllegalArgumentException. If the method is passed an array of length 0 or 1, the method should return true. Important: You must not modify the original array. 5. Write a method with the header public static int maxSorted(int[] values) that takes a reference to an array of integers and returns the length of the longest sorted sequence of integers in the array. For example: = int[] a7 {3, 8, 6, 14, -3, 0, 14, 207, 98, 12}; System.out.println(ArrayMethods.maxSorted(a7)); should display 4, because the longest sorted sequence in the array has four values in it (the sequence -3, 0, 14, 207). Note that the sorted sequence could contain duplicates. For example: = int[] a8 {17, 42, 3, 5, 5, 5, 8, 4, 6, 1, 19}; System.out.println(ArrayMethods.maxSorted(a8)); should display 5, since the longest sorted sequence is 3, 5, 5, 5, 8, which has a length of 5. Special cases: If the parameter is null, the method should throw an IllegalArgumentException. Your method should return 0 if passed an empty array (i.e., an array of length 0). Your method should return 1 if passed an array with one element or an array in which all of the elements are in decreasing order. It should be possible to get a return value of 1 for these cases without needing to explicitly check for them. Important: You must not modify the original array
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
