Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

27) In chapter 8, we worked on a number of array problems. Many were much more d

ID: 3677446 • Letter: 2

Question

27) In chapter 8, we worked on a number of array problems. Many were much more difficult than the Programming Project PP 8.5 on p. 436. However, surprisingly more than 50% of students did not get the correct answer(s) for this problem. One student in section 2, however nailed it. Below is his code. Examine the code below and from the M/C answers pick the one that best describes why this solution meets the specifications I discussed in class prior to assigning this problem.

A) The code correctly reflects the fact that the formula for the standard deviation that is given in the text on p. 436 is wrong

B) No user input is required

C) The array declaration and bounds checking is done correctly

D) All of the above

E) A and B only

/*********************************************************
2 // Statistics.java Author: Monti Lameg
3 //
4 // Programming Project 8.5
5 //********************************************************
6 import java.util.Arrays;
7
8 public class Statistics
9 {
10 public static void main(String[] args)
11 {

13 int[] numbers = {15, 16, 17, 18, 22, 24, 24, 13, 11, 10};
14
15 int sum = 0;
16 for (int i=0; i<numbers.length; i++)
17 {
18 sum = sum + numbers[i];
19 }
20 double mean = (double)sum / numbers.length;
21
22 double result = 0.0;
23 for (int i=0; i < numbers.length; i++)
24 result += Math.pow(numbers[i] - mean, 2);
25 double var = result/(numbers.length - 1);
26 double stDev = Math.sqrt(var);
27
28 System.out.println ("Mean: " + mean);
29 System.out.println("For the numbers: " + rrays.toString(numbers));
30 System.out.println ("Variance: " + var);
31
32 System.out.println ("Standard Deviation: " + stDev);
33 }
34 }

Explanation / Answer

B) No user input is required.

Here in this program the program is not taking data from the user.

Iti is already given in the array.

nt[] numbers = {15, 16, 17, 18, 22, 24, 24, 13, 11, 10};

Because the data is already given in numbers array the student processed it.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote