Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package console_apps; import java.util.Scanner; import model.Utilities; public class GetIntermediateStatsApp { public static void main(String[] args) { Scanner input = new Scanner(System.in); /* Prompt the user

package console_apps;
import java.util.Scanner;
import model.Utilities;
public class GetIntermediateStatsApp {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
/* Prompt the user for input bounds. */
System.out.println("Enter the first integer term of an arithmetic sequence:");
int ft = input.nextInt();
System.out.println("Enter the common difference of the sequence:");
int d = input.nextInt();
System.out.println("Enter the size of the sequence:");
int n = input.nextInt();
/* Invoke the utility method for calculation. */
String result = Utilities.getIntermediateStats(ft, d, n);
/* Output the result. */
System.out.println(result);
input.close();
}
}
/*
* 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;
}
image text in transcribed
/*
* Tests related to getIntermediateStats
*/
@Test
public void test_getIntermediateStats_01() {
String result = Utilities.getIntermediateStats(7, 3, 0);
assertEquals("{}", result);
}
@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 w inputs the first term (4), common difference (d), and size (1) of an arithmetic sequence. Based on these three input values, the corresponding arithmetic sequence (of n terme) is: (41. ta, si ....) where t = ft + (1 - 1).d and 1 Sisn The utility method should return a string value containing the following equal-sized sequence of statistical iteit where each statistical item (ISIS) reports the sum and average of the subsequence (.....) (of sizei). For example, the statistical item as reports the sun and average of the subsequence (h. 1. 6) (which, of course, is just a smaller arithmetic sequence). Requirement. It is strictly forbidden for you to use array of my library class (0.8., Arraytist). 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 cruses: study them while developing your code. However, the main application eines Get IntermediateStatsApp if you wish (ng the input and experter values from the JUnit tests). Here is an example ran Enter the first integer term of an arithmetic sequence: 23 Enter the common difference of the sequence: 11 Enter the size of the sequence: 2 [sun of : 23 : avg of : 23.00). (sum of : 28.50]} Todo. Implement the Utilities.getIntermediatestats method. See the comments there for the input parasti eters and requirements. The String return value must conform to the expected format: All statistical terms are wrapped within curly braces (0) and separated by cotnmas (.). Each statistical term is wrapped within square brackets (C) and reports the sum and average of the corte- 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(X.2f, someNumber). . In the above example, the arithmetic sequence implied by the three input value (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.09) [sum of : 102 ; avg of 23, 34, 45): 34.00) [sum of : 158 : avg of 23, 34, 45, 56): 39.50) [sum of : 45.60) All five statistical items above should be wrapped within curly braces ((!) and separated by comumas (). . 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

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

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago