Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java please! no array list use arrays and loops please import java.util.Scanner; import model.Utilities; public class GetAllPrefixesApp { public static void main(String[] args) { Scanner

image text in transcribedjava please! no array list use arrays and loops please

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(); }

}

utilities:

public static String[] getAllPrefixes(int[] numbers) { String[] result = null; /* Your implementation of this method starts here. * 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; }

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: 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

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

Public Finance Fundamentals

Authors: K. Moeti

3rd Edition

148512946X, 9781485129462

Students also viewed these Databases questions