Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

9.4 using interfaces for Callbacks 383 Rectangle Rectangle interface DataSet Fig

ID: 3841398 • Letter: 9

Question



9.4 using interfaces for Callbacks 383 Rectangle Rectangle interface DataSet Figure s UML Diagram of the DataSet class and the Measurer Interface The data set will ask the RectangleMeasurer object to measure the words, the data set uses the RectangleMeasurer object to carry rectangles. As Figure 5 shows the U diagram of the classes and interfaces of this solution. in Figure 2, the Dataset class is d from the Rectangle class whose objects However, unlike in Figure 2, the class is with another class. Instead, to process rectangles, you provide a small-b elper" class measure easure This helper class has only one purposes to tell the Dataset how its objects. easurerjava 2 Describes any class whose objects can measure other ob 4 public interface Measurer Computes the measure of an object. Gparan anobject the object to be measured are turn the measure 10 double measure (0bject anobject) 12 ch09/measure2/RectangleMeasurer,java l import java art.Rectangle; 4 Objects of this class measure rectangles by area. 6 public class RectangleMeasurer inplenents Measurer 8 public double measure(object anobject) Rectangle a Rectangle (Rectangle) an0bject double area aRectangle getwidtho aRectangle.getHeightoi 12 13

Explanation / Answer

public class Dataset {
  
   //add e new Objct in the class and
   //modify the add method as below
  
   private Object minimum;
  
   public void add(Object x){
      
       sum = sum + measurer.measure(x);
       if(count = 0 || measurer.measure(maximum) < measurer.measure(x))
           maximum = x;
       if(count = 0 || measurer.measure(minimum) > measurer.measure(x))
           minimum = x;
      
       count++;
   }

}