Question
java please! using arrays loops and no arraylists import java.util.Scanner; import model.Utilities; public class GetAllPrefixesApp { public static void main(String[] args) { Scanner input =
java please! using arrays loops and no arraylists
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 int[] getFilteredSeq(int[] numbers, int n) { int[] 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.2 Method to Implement: getFilteredSeq Problem. You are asked to implement a utility method which takes as input an array (say numbers) of integers and an integer (say n). Note that n may or may not exist in numbers. The utility method returns another array containing all elements in numbers that are not equal to n. For example, if the input n is 3 and the input array numbers is: Then the output or returned array is: Note that the length of the output array corresponds the number of elements in the input array that are not equal to n, meaning that if the input array is empty, or if n does not exist in the input array, then the output array should be just the same as the input array. Also, the output array should preserve the order in which elements appear in the input array. For example, in the above example, elements in the output array appear in the order of 1 followed by 2 and then by 4, which is reflected in the input array. 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 GetFilteredSeqApp 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: 2 Enter input 4: 3 Enter input 5: 4 Which number do you wish to filter from the input numbers? 3 Todo. Implement the Utilities.getFilteredSeq method. See the comments there for the input parameters and requirementsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started