Question: PrintPrime.java as mentioned. public class PrintPrimes { private static boolean isDivisible (int i, int j) { if (j%i == 0) return true; else return false;

PrintPrime.java as mentioned.
public class PrintPrimes
{
private static boolean isDivisible (int i, int j)
{
if (j%i == 0)
return true;
else
return false;
}
private static void printPrimes (int n)
{
int curPrime; // Value currently considered for primeness
int numPrimes; // Number of primes found so far.
boolean isPrime; // Is curPrime prime?
int [] primes = new int [100]; // The list of prime numbers.
// Initialize 2 into the list of primes.
primes [0] = 2;
numPrimes = 1;
curPrime = 2;
while (numPrimes
{
curPrime++; // next number to consider ...
isPrime = true;
for (int i = 0; i
{ // for each previous prime.
if (isDivisible (primes[i], curPrime))
{ // Found a divisor, curPrime is not prime.
isPrime = false;
break; // out of loop through primes.
}
}
if (isPrime)
{ // save it!
primes[numPrimes] = curPrime;
numPrimes++;
}
} // End while
// Print all the primes out.
for (int i = 0; i
{
System.out.println ("Prime: " + primes[i]);
}
} // end printPrimes
public static void main (String []argv)
{ // Driver method for printPrimes
// Read an integer from standard input, call printPrimes()
int integer = 0;
if (argv.length != 1)
{
System.out.println ("Usage: java PrintPrimes v1 ");
return;
}
try
{
integer = Integer.parseInt (argv[0]);
}
catch (NumberFormatException e)
{
System.out.println ("Entry must be a integer, using 1.");
integer = 1;
}
printPrimes (integer);
}
}
Question 2 (17 points) Consider the method printPrimes() for questions a below from the compliable version on Canvas -e in the file PrintPrimes.java. A line-numbered version suitable for this exercise is available on Canvas as Prime The following is a control flow graph for it Use this graph to answer questions a-e. nis initialized 1 num primes 1 11 isPrime true 12 numm Primes- i> 13 print isDivisiblelprimesl, curPrime) Prime false 6 break 14 NOT isPrime 15 9 primesinumPrimesl. curPrime 10 (a) Consider test cases tu n 3) and t2 (n 5). Although these tour the same prime paths in printPrimes(), they do not necessarily find the same faults. Design a simple fault that t2 would be more likely to discover than t would. (2 points) (b) For printPrimes0, find a test case such that the corresponding test path visits the edge that connects the beginning of the while statement to the for statement without going through the body of the while loop. 2 points) (c) List the test requirements for Node Coverage (1 point), and Edge Coverage (9 points) (d) List test paths that achieve Node Coverage but not Edge Coverage on the graph. (2 points (e) List test paths that achieve Edge Coverage but not Prime Path Coverage on the graph. (2 points) Question 2 (17 points) Consider the method printPrimes() for questions a below from the compliable version on Canvas -e in the file PrintPrimes.java. A line-numbered version suitable for this exercise is available on Canvas as Prime The following is a control flow graph for it Use this graph to answer questions a-e. nis initialized 1 num primes 1 11 isPrime true 12 numm Primes- i> 13 print isDivisiblelprimesl, curPrime) Prime false 6 break 14 NOT isPrime 15 9 primesinumPrimesl. curPrime 10 (a) Consider test cases tu n 3) and t2 (n 5). Although these tour the same prime paths in printPrimes(), they do not necessarily find the same faults. Design a simple fault that t2 would be more likely to discover than t would. (2 points) (b) For printPrimes0, find a test case such that the corresponding test path visits the edge that connects the beginning of the while statement to the for statement without going through the body of the while loop. 2 points) (c) List the test requirements for Node Coverage (1 point), and Edge Coverage (9 points) (d) List test paths that achieve Node Coverage but not Edge Coverage on the graph. (2 points (e) List test paths that achieve Edge Coverage but not Prime Path Coverage on the graph. (2 points)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
