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

--- Java --- FilteredData class and Measurable interface are included below. Cre

ID: 3662845 • Letter: #

Question

--- Java ---

FilteredData class and Measurable interface are included below.
Create an interface Filter

public interface Filter {

    boolean accept(Object o);

}

Modify FilteredData to optionally take a Filter on its constructor(s). A FilteredData object that has a Filter ignores Measurable objects that its filter does not accept.
Write a method to test your FilteredData object. Your tests should include

·       multiple FilteredData objects, at least one with no filter, others using a filter

·       at least two different Filter implementations

Measurable objects that both pass and don't pass the Filters

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

public interface Measurable {

     int getMeasure();

}

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

import java.util.ArrayList;

public class FilteredData {

     private ArrayList ds;

     private Measurable min;

     private Measurable max;

     public FilteredData() {

          ds = new ArrayList<>();

          min = null;

          max = null;

     }

     public void add(Measurable ele) {

          if ((min == null) || (min.getMeasure() > ele.getMeasure())) {

               min = ele;

          }

          if ((max == null) || (max.getMeasure() < ele.getMeasure())) {

               max = ele;

          }

          ds.add(ele);

     }

     public Measurable getMin() {

          return min;

     }

     public Measurable getMax() {

          return max;

     }

}

Explanation / Answer

public interface Measurable {
int getMeasure();
}

----------------------------------------------------------------------------------

public interface Filter {
boolean accept(Object o);
}

----------------------------------------------------------------------------------

import java.util.ArrayList;
public class FilteredData implements Measurable, Filter{
private ArrayList ds;
private Measurable min;
private Measurable max;
private Object o;
private Filter ft;
private int measurement;
public FilteredData() {
ds = new ArrayList<>();
min = null;
max = null;
}

public FilteredData(Object o) {
   this.o=o;
   }


  
   public void add(Measurable ele) {
if ((min == null) || (min.getMeasure() > ele.getMeasure())) {
min = ele;
}
if ((max == null) || (max.getMeasure() < ele.getMeasure())) {
max = ele;
}
ds.add(ele);
}
public Measurable getMin() {
return min;
}
public Measurable getMax() {
return max;
}

public static void main(String args[])
{
   Object o="NEW OBJECT";
   FilteredData newFData=new FilteredData(o);
   System.out.println(newFData.accept(o));
   FilteredData obj2=new FilteredData();
   Measurable ele=new Measurable() {
           @Override
           public int getMeasure() {
               // TODO Auto-generated method stub
               return 0;
           }
       };
   obj2.add(ele);
     
}
   public boolean accept(Object o) {
       if(o.equals(null))
           return false;
       else
           return true;
   }

   public int getMeasure() {
      
       return measurement;
   }
}