aboutsummaryrefslogtreecommitdiff
path: root/ap-computer-science-a-exam/q2.txt
blob: d9ae2aa2740307b0a2110b1ed1bc65761a84f31a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
WY5V8181
HR

(a)

public static boolean runSimulation(int sampleSize){
    int half = sampleSize/2;
    int halves[] = { 0, 0 };
    for (int i = 0; i < 2; i++){
        for (int j = 0; j < half; j++){
            int num = getInt();
            if (num > 0 && isTarget(num)) halves[i]++;
        }
    }
    return (halves[0] > halves[1]);
}

(b)

The programmer would, instead of using `int sampleSize` as a parameter,
use a `public final static int sampleSize = $value` where $value is the
value the programmer wants it to be so that it could be set at compile
time. If the programmer wants it to be set at runtime instead, the
programmer could use a basic class-wide declaration `private static int`
and setter public static void setSampleSize(int size) which would only
set the variable if it is non-null. Note that static is used for all
variables and methods because the class does not appear to use
instances.