diff options
Diffstat (limited to 'ap-computer-science-a-exam/q2.txt')
-rw-r--r-- | ap-computer-science-a-exam/q2.txt | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/ap-computer-science-a-exam/q2.txt b/ap-computer-science-a-exam/q2.txt new file mode 100644 index 0000000..d9ae2aa --- /dev/null +++ b/ap-computer-science-a-exam/q2.txt @@ -0,0 +1,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. |