Question: /* * Input parameters: * - `ft`, `d`, `n` are the first term, common difference, and size of an arithmetic sequence. * * Use of

 /* * Input parameters: * - `ft`, `d`, `n` are thefirst term, common difference, and size of an arithmetic sequence. * *

/* * Input parameters: * - `ft`, `d`, `n` are the first term, common difference, and size of an 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 getIntermediateStats(int ft, int d, int n) { 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_getIntermediateStats_02() { String result = Utilities.getIntermediateStats(7, 3, 1); String expected = "{[sum of : 7 ; avg of : 7.00]}"; assertEquals(expected, result); } @Test public void test_getIntermediateStats_03() { String result = Utilities.getIntermediateStats(7, 3, 2); String expected = "{"; expected += "[sum of : 7 ; avg of : 7.00]" + ", "; expected += "[sum of : 17 ; avg of : 8.50]"; expected += "}"; assertEquals(expected , result); } @Test public void test_getIntermediateStats_04() { String result = Utilities.getIntermediateStats(7, 3, 3); String expected = "{"; expected += "[sum of : 7 ; avg of : 7.00]" + ", "; expected += "[sum of : 17 ; avg of : 8.50]" + ", ";; expected += "[sum of : 30 ; avg of : 10.00]"; expected += "}"; assertEquals(expected, result); } @Test public void test_getIntermediateStats_05() { String result = Utilities.getIntermediateStats(7, 3, 4); String expected = "{"; expected += "[sum of : 7 ; avg of : 7.00]" + ", "; expected += "[sum of : 17 ; avg of : 8.50]" + ", "; expected += "[sum of : 30 ; avg of : 10.00]" + ", "; expected += "[sum of : 46 ; avg of : 11.50]"; expected += "}"; assertEquals(expected, result); }

2.2.2 Method to Implement: getIntermediateStats Problem. You are asked to implement a utility method which takes as inputs the first term (ft), common difference (d), and size (n) of an arithmetic sequence. Based on these three input values, the corresponding arithmetic sequence of n terms) is: (t1, tz, tz, ..., tre) where t; = ft +(i-1).d and 1 Sisn The utility method should return a string value containing the following equal-sized sequence of statistical items: (81, 82, 83, ..., 8) where each statistical item si (1 : 23 ; avg of : 23.00], [sum of : 57 ; avg of : 28.50]} Todo. Implement the Utilities.getIntermediateStats method. See the comments there for the input param- eters and requirements. The String return value must conform to the expected format: All statistical terms are wrapped within curly braces ({}) and separated by commas (.). Each statistical term is wrapped within square brackets ([]) and reports the sum and average of the corre- sponding sub-subsequence. Each sum is an integer and each average should be formatted as a floating-point number with 2 digits after the decimal point, using String.format(%.2f, someNumber). . In the above example, the arithmetic sequence implied by the three input values (23, 11, and 2) is 23, 34), and the output string contains the statistical items for the two sub-sequences: (23) and (23, 34). . As a slightly longer example, consider the statistical terms that should be included in the output string by input values 23 (first term), 11 (common difference), and 5 (size): [sum of : 23 ; avg of : 23.00] (sum of : 57 ; avg of : 28.50] [sum of : 102 ; avg of : 34.00] [sum of : 158 ; avg of : 39.50] [sum of : 225 ; avg of : 45.00] All five statistical items above should be wrapped within curly braces ({}) and separated by commas (,). There is one space before and after the semicolon (;). There is one space after each comma (,) and colon (:)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!