Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

* Input parameters: * - `ft1`, `d1`, `n1` are the first term, common difference, and size of the first arithmetic sequence. * - `ft2`, `d2`,

image text in transcribedimage text in transcribed* Input parameters: * - `ft1`, `d1`, `n1` are the first term, common difference, and size of the first arithmetic sequence. * - `ft2`, `d2`, `n2` are the second term, common difference, and size of the second arithmetic sequence. * * Use of arrays or any Java library class (e.g., ArrayList) is strictly forbidden. * Violation of this will result in a 50% penalty on your marks. * Try to solve this problem using loops only. * * Refer to you lab instructions for what the method should return. */ public static String getInterlevaings(int ft1, int d1, int n1, int ft2, int d2, int n2) { String result = ""; /* Your implementation of this method starts here. * 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. */ /* Your implementation ends here. */ return result; }

junit tests:

@Test public void test_getInterleavings_01a() { String result = Utilities.getInterlevaings(1, 2, 0, -1, -2, 0); assertEquals("", result); } @Test public void test_getInterleavings_01b() { String result = Utilities.getInterlevaings(1, 2, 0, -1, -2, 3); assertEquals("", result); } @Test public void test_getInterleavings_01c() { String result = Utilities.getInterlevaings(1, 2, 3, -1, -2, 0); assertEquals("", result); } @Test public void test_getInterleavings_03a() { String result = Utilities.getInterlevaings(1, 2, 3, -1, -2, 3); assertEquals("", result); } @Test public void test_getInterleavings_03b() { String result = Utilities.getInterlevaings(-23, -11, 5, 54, 17, 5); assertEquals("", result); } @Test public void test_getInterleavings_04a() { String result = Utilities.getInterlevaings(1, 2, 5, -1, -2, 3); assertEquals("", result); }

2.2.3 Method to Implement: getInterlevaings Problem. You are asked to implement a utility method which takes as inputs the first terms (f1, f2), common differences (d1, d2), and sizes (nl, and n2) of two arithmetic sequences. The utility method should return a string value containing a new sequence interleaving items drawn from the two arithmetic sequences. The interleaving starts from an item drawn from the first sequence, if it is not empty. For example, consider two arithmetic sequences with the same length: (3, 8) and (11, 4). Their interleaving is then (3, 11, 8, 4), where the 1st and 3rd items are drawn from the first arithmetic sequence, and the 2nd and 4th items are drawn from the second arithmetic sequence. In general, your implementation of the utility method should consider when the two arithmetic sequences are of different lengths (in which case the last items in the interleaving should be drawn from the longer arithmetic sequence). Requirement. It is strictly forbidden for you to use arrays or any library class (e.g., ArrayList). Violating this requirement will cause a 50% penalty on your lab marks. Testing. Your goal is to pass all tests related to this method in the JUnit test class TestUtilities. These tests document the expected values on various cases: study them while developing your code. However, use the console application class Get InterleavingsApp if you wish (e.g., use the input and expected values from the JUnit tests). Here are two example runs: Enter the first integer term of arithmetic sequence 1: 3 Enter the common difference of the sequence: 5 Enter the size of the sequence: 2 Enter the first integer term of arithmetic sequence 2: 11 Enter the common difference of the sequence: -7 Enter the size of the sequence: 2 Enter the first integer term of arithmetic sequence 1: 3 Enter the common difference of the sequence: 5 Enter the size of the sequence: 1 Enter the first integer term of arithmetic sequence 2: 11 Enter the common difference of the sequence: -7 Enter the size of the sequence: 3 Todo. Implement the Utilities.getInterlevaings method. See the comments there for the input parameters and requirements. The String return value must conform to the expected format: . All interleaved items should be wrapped within angle brackets () and separated by commas (). There is one space after each comma. Items drawing from the first arithmetic sequence should be wrapped within round parentheses (e.g., (3)). Items drawing from the second arithmetic sequence should be wrapped within square brackets (e.g., [11]). 9

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

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

Students also viewed these Databases questions