Question: this is the console app package console_apps; import java.util.Scanner; import model.Utilities; public class GetAllPrefixesApp { public static void main(String[] args) { Scanner input = new

this is the console app
package console_apps;
import java.util.Scanner;
import model.Utilities;
public class GetAllPrefixesApp { public static void main(String[] args) { Scanner input = new Scanner(System.in); /* Prompt the user for an array of numbers. */ System.out.println("How many numbers do you want to input?"); int howMany = input.nextInt(); int[] numbers = new int[howMany]; int i = 0; while(i "); input.close(); }
}
PLS NOTE THE CODE ABOVE IS GetAllPrefixesApp . DO NOT MODIFY!!!!!!!
package model;
/* * Requirements: * - Any use of Java library classes or methods (e.g., ArrayList) is forbidden. * (That is, there must not be an import statement in the beginning of this class.) * Violation of this requirement will result in a 50% penalty of your marks. * * - Use only if-statements and/or loops to manipulate primitive arrays (e.g., int[], String[]). */
public class Utilities { /* * Input parameters: * - `numbers` : an array of integers * * Refer to you lab instructions for what the method should return. */
/* * Input parameters: * - `numbers` : an array of integers * * Assumptions: * - numbers.length >= 1 * * Refer to you lab instructions for what the method should return. */ public static String[] getAllPrefixes(int[] numbers) { String[] result = null; /* Your implementation of this method starts here. * 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. */ /* Your implementation ends here. */ return result; }
PLS NOTE THE CODE ABOVE SHOULD BE MODIFIED TO DO THE TASK
/* * Tests related to getAllPrefixes */ @Test public void test_getAllPrefixes_01() { int[] input = {3}; String[] result = Utilities.getAllPrefixes(input); String[] expected = {"[3]"}; assertArrayEquals(expected, result); } @Test public void test_getAllPrefixes_02() { int[] input = {3, 1}; String[] result = Utilities.getAllPrefixes(input); String[] expected = {"[3]", "[3, 1]"}; assertArrayEquals(expected, result); } @Test public void test_getAllPrefixes_03() { int[] input = {3, 1, 4}; String[] result = Utilities.getAllPrefixes(input); String[] expected = {"[3]", "[3, 1]", "[3, 1, 4]"}; assertArrayEquals(expected, result); } @Test public void test_getAllPrefixes_04() { int[] input = {3, 1, 4, 5}; String[] result = Utilities.getAllPrefixes(input); String[] expected = {"[3]", "[3, 1]", "[3, 1, 4]", "[3, 1, 4, 5]"}; assertArrayEquals(expected, result); }
2.2.3 Method to Implement: getAllPrefixes Problem. You are asked to implement a utility method which takes as input an array of integers and returns another array of strings, each of which denoting a non-empty prefix of the input array. For example, if the input array is: Then the output or returned array of string values is: Note that the length of the output array is equal to the length of the input array. Also, elements in the output array are sorted by the lengths of the prefixes (e.g, the first element is the prefix of length 1, the second element is the prefix of length 2). Testing. Your goal is to first pass all tests related to this method in the JUnit test class TestUtilities. You are encouraged to write additional JUnit tests. These tests document the expected values on various cases: study them while developing your code. However, use the console application class GetAllPrefixesApp if you wish (e.g., use the input and expected values from the JUnit tests). Here is an example run: How many numbers do you want to input? 5 Enter input 1: 3 Enter input 2: 1 Enter input 3: Enter input 3: 4 Enter input 4: 2 Enter input 5: 5 Todo. Implement the Utilities.getAllPrefixes method. See the comments there for the input paramete and requirements
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
