Answered step by step
Verified Expert Solution
Question
1 Approved Answer
CODE **PLEASE SOLVE THE CODE USING JAVA PROGRAMMING** 2.2.2 Method to Implement: getIntermediateStats Problem. You are asked to implement a utility method which takes as
CODE
**PLEASE SOLVE THE CODE USING JAVA PROGRAMMING**
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, t2, t3, ., tn) where ti = ft+ (i 1)d and 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 angle 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] There is one space before and after the semicolon (;). There is one space after each comma (,) and colon (:). package console_apps; import java.util.Scanner;. 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. */ * * I /* Your implementation ends here. */ return 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, t2, t3, ., tn) where ti = ft+ (i 1)d and 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 angle 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] There is one space before and after the semicolon (;). There is one space after each comma (,) and colon (:). package console_apps; import java.util.Scanner;. 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. */ * * I /* Your implementation ends here. */ return result; }Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started