aboutsummaryrefslogtreecommitdiff
path: root/ap-computer-science-a-exam/q1.txt
diff options
context:
space:
mode:
Diffstat (limited to 'ap-computer-science-a-exam/q1.txt')
-rw-r--r--ap-computer-science-a-exam/q1.txt40
1 files changed, 40 insertions, 0 deletions
diff --git a/ap-computer-science-a-exam/q1.txt b/ap-computer-science-a-exam/q1.txt
new file mode 100644
index 0000000..fe2b68e
--- /dev/null
+++ b/ap-computer-science-a-exam/q1.txt
@@ -0,0 +1,40 @@
+WY5V8181
+HR
+
+(a)
+
+public double getCompoundAvg(String comp){
+ int ct = 0;
+ double totalTemp = 0;
+ for (Trial trial : trialList){
+ if (trial.getCompound() != comp) continue;
+ ct++;
+ totalTemp += trial.getTemp();
+ }
+ if (ct > 0) return totalTemp/ct;
+ else return -1;
+}
+
+(b)
+
+public String getCompoundWithHighestAvg(){
+ double max = -1; // less than all non-negative temperatures.
+ String compound;
+ for (String curCompound : getCompoundList()){
+ double avg = getCompoundAvg(curCompound);
+ if (avg > max){
+ max = avg;
+ compound = curCompound;
+ }
+ }
+ return compound;
+}
+
+(c)
+
+The programmer would need to add the amount of compound used as a
+private instance variable (with a getter) in Trial (which would be
+initialized in its constructor). ScienceExperiment would hold the method
+`public double getCompoundAmountUsed(String compoundName)` which would
+sum, for all Trials in trialList with the same compoundName as given,
+the value of trial.getAmountUsed(), and return that value.