Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

[Java]Write a class called Primes. The class should have the following: a. (1 po

ID: 3851329 • Letter: #

Question

[Java]Write a class called Primes. The class should have the following:

a. (1 point) A constructor. It is passed 2 parameters x and y, both of which are integers. You should write the class so that it can return a sequence of prime numbers between x and y (inclusive). For example, the prime numbers between 10 and 23 are 11, 13, 17, 19, and 23. b. (1 point) An isPrime method. It is passed a parameter p, and returns true if p is a prime number or false otherwise. c. (2 points) The class should implement the Iterable<Integer> interface. This means that the Primes class should have a method called iterator, which returns an object of type Iterator<Integer>. I have already written the iterator method; you must write hasNext and next for the Iterator<T> object returned by the iterator method.

Here is an example of code which uses the Primes class.

public class UsePrimes { public static void main(String[] args) {   int x=10, y=100; // x and y could be any integers as long as x<=y   Primes p = new Primes(x,y);    for (Integer i : p)    System.out.print(i + " ");   System.out.println(); } }

Here is the output that should be produced:

11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

Explanation / Answer

Please use Java 8 to compile and run the program:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote