blob: fe2b68e9c3456020907fd3a0274e5f31d4798a59 (
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
29
30
31
32
33
34
35
36
37
38
39
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.
|