Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN JAVA. DO NOT IMPORT ANY ARRAY OR MATH LIBRARIES. Please use a separate method and not the main method as mentioned below in the

IN JAVA. DO NOT IMPORT ANY ARRAY OR MATH LIBRARIES. Please use a separate method and not the main method as mentioned below in the todo section. Please do not use any array lists and only use arrays, for/while loops, and if statements.

image text in transcribed

UTILITY FILE:

image text in transcribed

THE CONSOLE APP CODE FOR TESTING:

image text in transcribed

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 (eg, 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: 4 Enter input 4: 2. Enter input 5: 5 Todo. Implement the Utilities.getAllPrefixes method. See the comments there for the input parameters and requirements. 98 99 100 1010 102 103 104 105 106 107 108 /* * Input parameters: "numbers : an array of integers * * * Assumptions: - numbers. length >= 1 * * 109 * 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. anner operations should appear here (e.g., input.nextInt()). * Instead, refer to the input parameters of this method. */ 1106 111 112 113 114 115 116 11 118 119 120 121 122 123 124 125 126 127 128 129 130 /* Your implementation ends here. */ return result; } 18 i ++; 1 package console_apps; 2 30 import java.util.Scanner;. 6 7 public class GetAllPrefixesApp { 8 ge public static void main(String[] args) { 10 Scanner input = new Scanner(System.in); 11 12 /* Prompt the user for an array of numbers. */ 13 System.out.println("How many numbers do you want to input?"); 14 int howMany = input.nextInt(); 15 int[] numbers = new int[howMany]; 16 int i = 0; 17 while(i "); 36 37 input.close(); 38 } 39 40 } 41 27 33

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 19c DBA By Examples Installation And Administration

Authors: Ravinder Gupta

1st Edition

B09FC7TQJ6, 979-8469226970

More Books

Students also viewed these Databases questions

Question

5. A review of the key behaviors is included.

Answered: 1 week ago

Question

3. An overview of the key behaviors is presented.

Answered: 1 week ago