Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. 2. ** please respond using Java** * Input Parameters: * - seg: an array of integers * indices': an array of integers (each of

1.

image text in transcribed

2.

image text in transcribed

** please respond using Java**

* Input Parameters: * - seg: an array of integers * indices': an array of integers (each of which may or may not be a valid index for "seg") * Assumptions: * seg may be empty. * 'indices may be empty. 'indices may contain duplicates. * What to return? * - For each integer value in 'indices', if it is a valid index for input array `seq' then use it to index into `seq' and include the result in the output array. For example: Say `seq' is {23, 46, 69} and `indices' is {2, -1, 0, 3, 0, 2} (where indices -1 and 3 are invalid, so only indices 2, 0, 0, 2 are used) Then the method should return {69, 23, 23, 69} * Note: Order of elements in the output array corresponds to the order in which valid indices in the 'indices' array are arranged. That is, the output array may be empty if the input array `seg is empty, or if the input array 'indices does not contain any valid indices. * * * * * * * See the JUnit tests related to this method. */ public static int[] task1(int[] seq, int[] indices) { int[] result = null; * 7* Your task is to implement this method, * so that running TestUtilities.java will pass all JUnit tests. * 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. * 3. Do not re-assign any of the parameter/input variables. */ * // Your implementation of this method starts here. // Do not modify this return statement. return result; } * * * * * * * /* * Input Parameters: * seg: a non-empty array of integers * * Assumptions: * - Input array `seg' is not empty. * * What to return? * - Return an array that represents an encoding of seg, by adopting the following principle: Element at each odd index (e.g., at index i, at index 3, and so on) of the return array specifies how many times the element at the previous even index (e.g., at index 0, at index 2, and so on) repeats in the input array seg. For example, {2, 4, 1, 3} encodes that value 2 (at even index () should repeat 4 times (as specified at odd index 1), and similarly, value 1 should repeat 3 times. Say `seq' is {2, 2, 2, 2, 1, 1, 1}. Then the method should return an encoded array {2, 4, 1, 3}. * See the JUnit tests related to this method. */ public static int[] task2(int[] seq) { int[] result = null; /* Your task is to implement this method, * so that running TestUtilities.java will pass all JUnit tests. * * 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. * 3. Do not re-assign any of the parameter/input variables. */ * * // Your implementation of this method starts here. // Do not modify this return statement. return result; }

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 Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions

Question

Factor the polynomials. x 3 + 125

Answered: 1 week ago

Question

3. What might you have done differently

Answered: 1 week ago

Question

4. Did you rethink your decision?

Answered: 1 week ago

Question

3. Did you seek anyones advice?

Answered: 1 week ago