package hwk1; /** * Homework 1 * @author Logan Morgan, this is my own work. * Determines if elements from an array are prime, perfect square, or negative * numbers. */ public class Clmorga4_hwk1{ public static boolean contains( T[] input, Check c){ for(int i=0;i{ boolean ok(T item); } 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){ for(int i=2; i{ public boolean ok(Integer val){ double sqrt=Math.sqrt(val); int casting=(int)(sqrt);//cast to an integer if(sqrt%casting==0){ return true; } else 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); System.out.println(result2); System.out.println(result3); } }