/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package hw1; /** * @author Bacta */ public class eewest_hwk1 { public static void main(String[] args) { Number[] input = { -100.02}; System.out.println("Input:"+ input[0].floatValue()); System.out.println("IsPrime? :"+Contains(input, new Prime())); System.out.println("IsPerfectSq?:"+Contains(input, new PerfectSquare())); System.out.println("IsNegative? :"+Contains(input, new Negative())); input[0] = 64.02; System.out.println("Input:" + input[0].floatValue()); System.out.println("IsPrime? :"+Contains(input, new Prime())); System.out.println("IsPerfectSq?:"+Contains(input, new PerfectSquare())); System.out.println("IsNegative? :"+Contains(input, new Negative())); input[0] = 11.02; System.out.println("Input:" + input[0].floatValue()); System.out.println("IsPrime? :"+Contains(input, new Prime())); System.out.println("IsPerfectSq?:"+Contains(input, new PerfectSquare())); System.out.println("IsNegative? :"+Contains(input, new Negative())); } static boolean Contains(T[] arr, Parameter P) { if(P instanceof Prime){ for (int i = 0; i < arr.length; i++) { T temp = arr[i]; if(temp.intValue() != temp.doubleValue()){ continue; } for (int j = 2; j <= (temp.intValue()/2); j++) { if((temp.intValue() % j) == 0){ break; }else if (j == (temp.intValue()/2)){ return true; } } } }// End of P == Prime if(P instanceof Negative){ for (int i = 0; i < arr.length; i++) { if(arr[i].doubleValue() < 0){ return true; } } }// End of P == Negative if(P instanceof PerfectSquare){ for (int i = 0; i < arr.length; i++) { if(arr[i].doubleValue() != arr[i].intValue()){ continue; } double temp1 = Math.sqrt(arr[i].intValue()); int temp2 = (int) temp1; if(temp1 == temp2){ return true; } } }// End of P == PerfectSquare return false; } } class Prime implements Parameter { } class Negative implements Parameter { } class PerfectSquare implements Parameter { } interface Parameter { }