Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How to do this please help ASAP don't use Any Java library class (e.g., ArrayList, Arrays) package model; public class Utilities { /* * Requirements:

How to do this please help ASAP

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

package model;

public class Utilities { /* * 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.) * - You will receive an immediate zero for this task if the requirement is violated. * - You can define helper methods if you wish. * * Only write lines of code within the methods given to you. * Do not declare any variables OUTSIDE the given methods. * You can only declare local variables within each method. * * Your submission will only be graded against: * - JUnit tests given to you in TestUtilities * - additional JUnit tests */ /* * Input Parameters: * - `seq`: a non-empty array of integers * * Assumptions: * - Input array `seq` is not empty. * * What to return? * - Return another array of strings, each of which denoting a non-empty suffix of the input array. * * A suffix of array `seq` contains its last n elements (where 1 <= n <= seq.length). * * For example, if the input array is: * * <3, 1, 4> * * Then the output or returned array of string values is: * * <"[3, 1, 4]", "[1, 4]", "[4]"> * * where each suffix is structured as a comma-separated list surrounded by square brackets. * * Note that the length of the output array is equal to the length of the input array. * * Also, elements in the output array are ``sorted'' by the lengths of the suffixes. * (e.g,. the last element is the suffix of length 1, the second last element is the suffix of length 2). * * See the JUnit tests related to this method. */

/* * 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

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

0805302441, 978-0805302448

More Books

Students also viewed these Databases questions

Question

=+2. What functions can be localized in particular areas of cortex?

Answered: 1 week ago