Goals:
public static int findPrimeFactor (List<Integer> a, List<Integer> b) // Requires: a not null; b not null; // there is some index i where b[i] is // both prime and a factor of a[i] // // Effects: return the least index // at which b[i] is a prime factor of a[i] // E.g. findPrimeFactor ([12, 25, 18, 8], [6, 2, 3, 2]) = 2 // (Note: 6 is a factor of 12, but is not prime, // and 2 is prime, but is not a factor of 25. However, // 3 is a prime factor of 18. Hence, index "2" is the correct // answer. index "3" is not a possible answer, because the // third index is not the least index with the desired property.) // Also note that a[] and b[] need not be of the same length.Implement this method in a class called
FindPrimeFactor
.
Although you should (obviously) test your implementation yourself,
you do not need to include any test code.
The GTA will test your code.
Note that error checking in findPrimeFactor()
for parameters that do not satisfy the precondtions
is not necessary
(or even permitted, if you happen to follow Meyer).
We will discuss this point in detail in class
when we cover exception handling.