import java.math.BigInteger; /** A common interface for the primality tests we'll look at. */ public abstract class PrimalityTest { public abstract boolean isPrime(BigInteger n); public void timedPrimeTest(BigInteger n) { System.out.println("Running test: " + getClass().getName()); System.out.println("n: " + n); long startTime = System.currentTimeMillis(); System.out.println("Prime?: " + isPrime(n)); long elapsedTime = System.currentTimeMillis() - startTime; System.out.println("Time taken: " + elapsedTime + " milliseconds."); } }