public interface Measurable INTERFACE { double getMeasure(); } public interface
ID: 3636749 • Letter: P
Question
public interface Measurable INTERFACE{
double getMeasure();
}
public interface Measurer CALLBACK
{
double measure(Object anObject);
}
public class RectangleMeasurer implements Measurer
{
public double measure(Object anObject)
{
Rectangle aRectangle = (Rectangle) anObject;
double area = aRectangle.getWidth() * aRectangle.getHeight();
return area;
}
}
public DataSet(Measurer aMeasurer)
{
sum = 0;
count = 0;
maximum = null;
measure = aMeasurer;
}
public void add(Object x)
{
sum = sum + measurer.measure(x);
If (count == 0 || measurer.measure(maximum) < measurer.measure(x))
maximum = x;
count++;
}
Measure m = new RectangleMeasurer();
DataSet data = new DataSet(m);
data.add(new Rectangle(5,10,20,30));
data.add(new Rectangle(10,20,30,40));
Question:
What are the values of variables of "sum" and "count" at the end of the block "OPERATIONS"?
Explanation / Answer
http://www.iro.umontreal.ca/~pift1025/bigjava/Ch11/ch11.html http://horstmann.com/sjsu/cs46a/ch09/ch09.html
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.