JAVA PROGRAMMING: Modify the following class to be a generic class. The generic
ID: 3666580 • Letter: J
Question
JAVA PROGRAMMING:
Modify the following class to be a generic class. The generic types usable by FilteredData should implement the Comparable interface. Your tester (whether it be a tester class with a main method or a JUnit class) should test your new FilteredData class with at least two different generic types, say String and Integer, for example.
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 class BST { private class BSTNode implements Comparable { BSTNode left, right; E data; @Override public int compareTo(E o) { return 0;//implement method here } } private BSTNode root; public BST() { root = new BSTNode();//while comparing you would need to case E to comparable and call compareTo method } public static void main(String[] args) { BST messages = new BST(); } }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.