/* * * Name: Meeka Haith-Woods * CSC-330 Homework Assignment #1 * Due Date: 1/27/2014 */ class mlhaithw_hkw1 { public static boolean contains(T[] input, Check c) { for(int i=0; i < input.length; i++) { c.ok(input[i]); } return false; } public static interface Check { boolean ok(T item); } public static class Negative implements Check { public boolean ok(Integer value) { return value < 0; } } public static class Prime implements Check { public boolean ok(Integer value) { for(int i=2;i<=Math.sqrt(value);i++){ if (value%i == 0) return false;} return true; } } public static class PerfectSquare implements Check { public boolean ok(Integer value) { double sqroot=Math.sqrt(value); if(sqroot == Math.ceil(sqroot))return true; return false; } } public static void main(String[] args) { int[] input = {100, 37, 49}; boolean result1 = contains(input, new Prime( )); boolean result2 = contains(input, new PerfectSquare( )); boolean result3 = contains(input, new Negative( )); } }