//CSC 330 //Student: Luning Deng //This is my own work //1/25/2014 public class L_Deng_hwk1{ /** * * @param */ public static interface Check { boolean ok(T item); } /** * Negative to implement Check and its method is to check if it is negative */ public static class Negative implements Check { @Override public boolean ok( Integer val) { return val < 0; } } /** * This PerfectSquare class implements Check interface and its ok method * Its method is to test if it is perfectSquare */ public static class PerfectSquare implements Check { /** * * @param val * @return true if it is perfect square otherwise false */ @Override public boolean ok( Integer val) { if(val<0) return false; if (val == 1) return true; if(val==0) return true; long curSquare = 4; long curNumber = 2; while (curSquare <= val) { if (curSquare == val) return true; curNumber++; curSquare = curNumber * curNumber; } return false; } } /** * This Prime class implements Check interface and its ok method * The method is to test if it is prime */ public static class Prime implements Check { /** * * @param val * @return true if it is a prime otherwise false */ @Override public boolean ok( Integer val) { if (val%2==0) return false; for(int i = 3; i * i <= val; i += 2){ if (val % i == 0) return false; } return true; } } /** * * @param array * @param input array * @param c * @return true if the object contains a specific value * it uses for loop to test every value in the */ public static boolean contains( T[] input, Check c) { boolean a=false; for(int i=0;i