/* * I have abided by the UNCG Academic Integrity Policy on this assignment * James Gray Spinks * 1/27/14 * CSC 330 */ class jgspinks_hwk1 { public static boolean contains(T[] input, Check c) { int i = 0; while(i < input.length){ if(c.ok(input[i])){ return true; } i++; } return false; } static public interface Check { boolean ok( T item); //item T is ok (negative e.g.) } static public class Negative implements Check { public boolean ok(Integer val) { return val < 0; } } static public class Prime implements Check { public boolean ok(Integer val) { if(val%2==0){ return false; } int i = 3; while(i*i { public boolean ok(Integer val){ int i = 1; while(i*i<=val){ if(val/i == i && val%i == 0){ return true; } i++; } return false; } } public static void main(String[] args){ Integer[] input = {100, 37, 49}; boolean result1 = contains(input, new Prime()); boolean result2 = contains(input, new PerfectSquare()); boolean result3 = contains(input, new Negative()); System.out.println(result1 + " " + result2 + " " + result3); } }