Presentation is loading. Please wait.

Presentation is loading. Please wait.

ArrayList Day 3 Be able to read AP Mult Choice questions tied to ArrayLists Be able to write a program that uses ArrayLists that analyzes numbers.

Similar presentations


Presentation on theme: "ArrayList Day 3 Be able to read AP Mult Choice questions tied to ArrayLists Be able to write a program that uses ArrayLists that analyzes numbers."— Presentation transcript:

1 ArrayList Day 3 Be able to read AP Mult Choice questions tied to ArrayLists Be able to write a program that uses ArrayLists that analyzes numbers.

2 Sample Question 2. Consider the following code segment.
ArrayList <Integer> list = new ArrayList<Integer> (); list.add(new Integer(1)); list.add(new Integer(2)); list.add(new Integer(3)); list.set(2, new Integer(4)); list.add(2, new Integer(5)); list.add(new Integer(6)); System.out.println(list); What is printed as a result of executing the code segment? (A) [1, 2, 3, 4, 5] (B) [1, 2, 4, 5, 6] (C) [1, 2, 5, 4, 6] (D) [1, 5, 2, 4, 6] (E) [1, 5, 4, 3, 6] Note: This will display the entire arraylist!! Same as System.out.println(list.toString());

3 3. Consider the following data field and method.
private ArrayList nums; // precondition: nums.size() > 0; // nums contains Integer objects public void numQuest() { int k = 0; Integer zero = new Integer(0); while (k< nums.size()) if (nums.get(k).equals(zero)) nums.remove(k); k++; } Assume that ArrayList nums initially contains the following Integer values. [0, 0, 4, 2, 5, 0, 3, 0] What will ArrayList nums contain as a result of executing numQuest ? (A) [0, 0, 4, 2, 5, 0, 3, 0] (B) [4, 2, 5, 3] (C) [0, 0, 0, 0, 4, 2, 5, 3] (D) [3, 5, 2, 4, 0, 0, 0, 0] (E) [0, 4, 2, 5, 3]

4 Program Input: 10 scores (integers) Output:
The high score The low score The average The number of scores within 3 of the average Push: Support an unknown number of scores Push: Show the numbers in order low to high Input: 10 scores and calculate the standard deviation

5 Standard Deviation Example.
Find the standard deviation of 4, 9, 11, 12, 17, 5, 8, 12, 14 First work out the mean (Average, xbar,…): ( )/9 = Now, subtract the mean individually from each of the numbers in the question and square the result. This is equivalent to the (x - xbar)² step. x refers to the values in the question. x               4        9        11       12       17       5       8       12      14 (x - xbar)²     38.7   1.49    0.60    3.16    45.9   27.3   4.94     14.3 Now add up these results (this is the 'sigma' in the formula): 139.55 Divide by n-1. n is the number of values, so in this case n-1 is 8: / 8 = 17.44 And finally, square root this: 4.18


Download ppt "ArrayList Day 3 Be able to read AP Mult Choice questions tied to ArrayLists Be able to write a program that uses ArrayLists that analyzes numbers."

Similar presentations


Ads by Google