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. */ public static String[] task1(int[] seq) { String[] 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 junit test

package junit_tests;

import static org.junit.Assert.*;

import org.junit.Test;

import model.Utilities;

public class TestUtilities { /* * Tests related to Task 1 */ @Test public void test_task1_01() { int[] input = {3}; String[] result = Utilities.task1(input); String[] expected = {"[3]"}; assertArrayEquals(expected, result); } @Test public void test_task1_02() { int[] input = {3, 1}; String[] result = Utilities.task1(input); String[] expected = {"[3, 1]", "[1]"}; assertArrayEquals(expected, result); } @Test public void test_task1_03() { int[] input = {3, 1, 4}; String[] result = Utilities.task1(input); String[] expected = {"[3, 1, 4]", "[1, 4]", "[4]"}; assertArrayEquals(expected, result); } @Test public void test_task1_04() { int[] input = {3, 1, 4, 5}; String[] result = Utilities.task1(input); String[] expected = {"[3, 1, 4, 5]", "[1, 4, 5]", "[4, 5]", "[5]"}; assertArrayEquals(expected, 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 Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

More Books

Students also viewed these Databases questions