at many prime numbers. Iterator() returns an Iterator object that will iterate through the primes, and toString() returns a string representation.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

 

Consider the following class PrimeNumbers, which has three methods. The first, computePrimes() takes one integer input and calculates that many prime numbers. Iterator() returns an Iterator object that will iterate through the primes, and toString() returns a string representation.

 

public class PrimeNumbers implements Iterable<Integer>

{

private List<Integer> primes = new ArrayList<Integer>();

public void computePrimes (int n)

{

int count = 1; // count of primes

int number = 2; // number tested for primeness

boolean isPrime; // is this number a prime

while (count <= n)

{

isPrime = true;

for (int divisor = 2; divisor <= number / 2; divisor++)

{

if (number % divisor == 0)

{

isPrime = false;

break; // for loop

}

}

if (isPrime && (number % 10 != 9)) // FAULT

{

primes.add (number);

count++;

}

number++;

}

}

 

@Override public Iterator<Integer> iterator()

{

return primes.iterator();

}

 

2

 

@Override public String toString()

{

return primes.toString();

}

}

 

computePrimes() has a fault that causes it not to include prime numbers whose last digit is 9 (for example, it omits 19, 29, 59, 79, 89, 109, ...).

 

Normally, this problem is solved with the Sieve of Eratosthenes. The change in algorithm changes the consequences of the fault. Specifically, false positives are now possible in addition to false negatives.

 

(a) Reimplement the algorithm for calculating primes using the Sieve of Eratosthenes approach, but leave the fault in place.

 

(b) What is the first false positive and how many primes must a test case generate before encountering it?

 

(c) A test must reach a location in a program that contains the fault (reachability). After the location is executed, the state of the program is incorrect (infected). The infected state must propagate through the execution and cause some output of the final state of the program to be incorrect (propagation). Finally, the tester must observe part of the incorrect portion of the final program state (revealability). (This all serves to illustrate that testing is actually really complicated!) What does this example illustrate about these four concepts

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education