Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a Junit test that reveals the fault for the following input. The keyword Reveal has a special meaning in RIPR model, and be sure
Write a Junit test that reveals the fault for the following input. The keyword Reveal has a special meaning in RIPR model, and be sure to go over it in the RIPR
(Chapter-2) model before answering this question.
Code is below :
import java.util.*; public class PrimeNumbers implements Iterable{ private List primes = new ArrayList (); /* * creates a list of n prime numbers * * @param n - the number of primes to compute silently treats negative * arguments as zero */ 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)) { // THIS IS THE FAULT!!! primes.add(number); count++; } number++; } } @Override public Iterator iterator() { return primes.iterator(); } @Override public String toString() { return primes.toString(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started