Question: 1 . ( 6 0 points ) Use the method printPrimes ( ) for questions a - f below. ` ` ` private static void

1.(60 points) Use the method printPrimes() for questions a-f below.
```
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 n)
{
curPrime++; // next number to consider ...
isPrime = true;
for (int i =0; i = numPrimes-1; 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 = numPrimes-1; i++)
{
}
System.out.println ("Prime: "+ primes[i]);
}// end printPrimes
```
a.(10 points) Draw the control flow graph for the printPrimes() method.
b.(10 points) Consider test cases \(\mathrm{t}1=(\mathrm{n}=3\)) and \(\mathrm{t}2=(\mathrm{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 t1 would.
c.(10 points) For printPrimes(), 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.
d.(10 points) List the test requirements for Node Coverage, Edge Coverage, and Prime Path Coverage.
e.(10 points) List test paths that achieve Node Coverage but not Edge Coverage on the graph.
f.(10 points) List test paths that achieve Edge Coverage but not Prime Path Coverage on the graph. 2. Use the following program fragment for questions a-e below.
```
w = x;
if (m >0)
{
w++; // node 2
}
else
{
w=2*w; // node 3
}
// node 4(no executable statement)
if (y =10)
{
x =5*y; // node 5
}
else
{
x =3*y+5; // node 6
}
z = w + x; // node 7
```
a.(10 points) Draw a control ow graph for this program fragment. Use the node numbers given above.
b.(10 points) Which nodes have defs for variable w?
c.(10 points) Which nodes have uses for variable w?
d.(10 points) Are there any du-paths with respect to variable \( w \) from node 1 to node 7? If not, explain why not. If any exist, show one.
e.(10 points) List all of the du-paths for variables \( w \) and \( x \).
1 . ( 6 0 points ) Use the method printPrimes ( )

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!