Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help ASAP don't use Any Java library class (e.g., ArrayList, Arrays) /* * Input Parameters: * - `seq`: a non-empty array of integers *

please help ASAP

don't use Any Java library class (e.g., ArrayList, Arrays)

/* * Input Parameters: * - `seq`: a non-empty array of integers * - `n`: a non-negative integer * * Assumptions: * - Input array `seq` is not empty. * - Input integer `n` is non-negative (>= 0). * * What to return? * - Given an array `seq` of integers and an integer `n`, * return a new array whose elements correspond to those of `seq` by * shifting every element in `seq` to the right by `n` positions. * - The shifts are ***circular***: * any elements that would "go off the boundary" are * wrapped around back from the beginning of the array. * * See the JUnit tests related to this method. */ public static int[] task2(int[] seq, int n) { 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; }

the unit tests:

/* * Tests related to Task 2 */ @Test public void test_task2_01() { int[] seq = {1, 2, 3, 4, 5}; int[] expected = {1, 2, 3, 4, 5}; assertArrayEquals(expected, Utilities.task2(seq, 0)); } @Test public void test_task2_02() { int[] seq = {1, 2, 3, 4, 5}; int[] expected = {5, 1, 2, 3, 4}; assertArrayEquals(expected, Utilities.task2(seq, 1)); } @Test public void test_task2_03() { int[] seq = {1, 2, 3, 4, 5}; int[] expected = {2, 3, 4, 5, 1}; assertArrayEquals(expected, Utilities.task2(seq, 4)); } @Test public void test_task2_04() { int[] seq = {1, 2, 3, 4, 5}; int[] expected = {3, 4, 5, 1, 2}; assertArrayEquals(expected, Utilities.task2(seq, 8)); }

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 Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions