Question: * Requirements: * - It is strictly forbidden for you to use: * + Any Java library method (e.g., Arrays.sort) * (That is, there must
* Requirements: * - It is strictly forbidden for you to use: * + Any Java library method (e.g., Arrays.sort) * (That is, there must not be an import statement in the beginning of this class.) * + arrays * - You will receive an immediate zero for this task if the requirement is violated. * * Input Parameters: * - `n1`: first number * - `n2`: second number * - `n3`: third number * - `n4`: fourth number * Note. These four input numbers are not necessarily unique. They might contain duplicates. * * Error conditions (in order of priority): * - None. No error message is needed. * * What to return? * - Return a report of the smallest number and the second smallest number. * * See the JUnit tests related to this method for the precise format of the string return value. */ public static String getSmallestTwoNumbers(int n1, int n2, int n3, int n4) { String result = ""; /* Your task is to implement this method, * so that running TestUtilities.java will pass all JUnit tests. * * Recall from Week 1's tutorial videos: * 1. No System.out.println statements should appear here. * Instead, an explicit, final `return` statement is placed for you. * 2. No Scanner operations should appear here (e.g., input.nextInt()). * Instead, refer to the input parameters of this method. * 3. Do not re-assign any of the parameter/input variables. */ // Your implementation of this method starts here. // Do not modify this return statement. return result; }
Junit tests
@Test public void test_getLargestTwoNumbers_01() { String result = Utilities.getSmallestTwoNumbers(1, 2, 3, 4); assertEquals("smallest is 1 and second smallest is 2", result); } @Test public void test_getLargestTwoNumbers_02() { String result = Utilities.getSmallestTwoNumbers(4, 3, 2, 1); assertEquals("smallest is 1 and second smallest is 2", result); } @Test public void test_getLargestTwoNumbers_03() { String result = Utilities.getSmallestTwoNumbers(3, 2, 4, 1); assertEquals("smallest is 1 and second smallest is 2", result); } @Test public void test_getLargestTwoNumbers_04() { String result = Utilities.getSmallestTwoNumbers(3, 2, 4, 2); assertEquals("smallest is 2 and second smallest is 2", result); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
