import java.util.Arrays;
import java.util.List;
public class Main {
public static void main(String[] args) {
NumberGroup group1 = new IntegerList(Arrays.asList(100, 200));
System.out.println(group1.contains(100)); // true
System.out.println(group1.contains(300)); // false
}
// specific interface it is asking for part a
public interface NumberGroup {
boolean contains(int num);
}
public static class IntegerList implements NumberGroup {
private List<Integer> numbers;
public IntegerList(List<Integer> numbers) {
this.numbers = numbers;
}
@Override
public boolean contains(int num) {
return numbers.contains(num);
}
}
}
Main.main(null)
public class Main {
public static void main(String[] args) {
NumberGroup range1 = new Range(100, 200);
System.out.println(range1.contains(150));
System.out.println(range1.contains(175));
System.out.println(range1.contains(300));
}
public interface NumberGroup {
boolean contains(int num);
}
public static class Range implements NumberGroup {
private int min;
private int max;
public Range(int min, int max) {
this.min = min;
this.max = max;
}
@Override
public boolean contains(int number) {
return number >= min && number <= max;
}
}
}
Main.main(null)
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
List<NumberGroup> groups = new ArrayList<>();
groups.add(new Range(100, 200));
groups.add(new Range(300, 400));
groups.add(new Range(500, 600));
MultipleGroups multiple1 = new MultipleGroups(groups);
System.out.println(multiple1.contains(150)); // true
System.out.println(multiple1.contains(250)); // false
System.out.println(multiple1.contains(550)); // true
}
// from part A
public interface NumberGroup {
boolean contains(int num);
}
// from part B
public static class Range implements NumberGroup {
private int min;
private int max;
public Range(int min, int max) {
this.min = min;
this.max = max;
}
@Override
public boolean contains(int num) {
return num >= min && num <= max;
}
}
public static class MultipleGroups implements NumberGroup {
private List<NumberGroup> groupList;
public MultipleGroups(List<NumberGroup> groupList) {
this.groupList = groupList;
}
public boolean contains(int num) {
for (NumberGroup group : groupList) {
if (group.contains(num)) {
return true;
}
}
return false;
}
}
}
Main.main(null);