Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please do it in JAVA, Requirements: * - It is strictly forbidden for you to use: * + Any Java library class (e.g., ArrayList, Arrays)

Please do it in JAVA,

Requirements: * - It is strictly forbidden for you to use: * + Any Java library class (e.g., ArrayList, Arrays) * (That is, there must not be an import statement in the beginning of this class.)

/* * 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 left 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[] task1(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. */

/* * Tests related to Task 1 */ @Test public void test_task1_01() { int[] seq = {1, 2, 3, 4, 5}; int[] expected = {1, 2, 3, 4, 5}; assertArrayEquals(expected, Utilities.task1(seq, 0)); } @Test public void test_task1_02() { int[] seq = {1, 2, 3, 4, 5}; int[] expected = {2, 3, 4, 5, 1}; assertArrayEquals(expected, Utilities.task1(seq, 1)); } @Test public void test_task1_03() { int[] seq = {1, 2, 3, 4, 5}; int[] expected = {5, 1, 2, 3, 4}; assertArrayEquals(expected, Utilities.task1(seq, 4)); } @Test public void test_task1_04() { int[] seq = {1, 2, 3, 4, 5}; int[] expected = {4, 5, 1, 2, 3}; assertArrayEquals(expected, Utilities.task1(seq, 8)); }

Shoudl pass all these tests

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

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions