Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

NMOOOO 16 i ++; 1 package console_apps; 2 30 import java.util.Scanner:0 6 7 public class GetGrouped NumbersApp { 8 90 public static void main(String[] args)

image text in transcribed
image text in transcribed
image text in transcribed
NMOOOO 16 i ++; 1 package console_apps; 2 30 import java.util.Scanner:0 6 7 public class GetGrouped NumbersApp { 8 90 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); int i = 0; 17 while(i "); 36 37 input.close(); 38 39 40 } 41 /* * Input parameters: * = numbers: an array of integers * Refer to you lab instructions for what the method should return. */ public static int[] getGroupedNumbers(int[] numbers) { int[] result = null; 1* 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; } Problem. You are asked to implement a utility method which takes as input an array of integers and returns another array grouping all elements from the input array as follows, from left to right: 1) elements divisible by 3:2) elements divided by 3 with the remainder 1; and 3) elements divided by 3 with the remainder 2. For example, if the input array is Then the output or returned array is: . Group 1 Group Grow Note that the input and output arrays are equally long, meaning that if the input array is empty, then the output array should be empty Also, each group of the output array should preserve the order in which its elements appear in the input array For example, in the above example, Group 2 of the output array (le, those divided by 3 with the remainder 1) contains 4 followed by 1, reflecting their order 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 Get Grouped NumbersApp 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? 10 Enter input 1: 89 Enter input 2: 22 Enter input 3: 42 Enter input 4: B7 Enter input 5: 19 I Enter input 6: 36 Enter input 7: 23 Enter input 8: 97 Enter input 9: 102 Enter input 16: 987

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

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

Students also viewed these Databases questions