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

Write a class PrimeSequence that implements the Sequence interface of Worked Exa

ID: 3842369 • Letter: W

Question

Write a class PrimeSequence that implements the Sequence interface of Worked Example 10.1* and produces a sequence of prime numbers.

USE THIS BELOW AS AN EXAMPLE, MODIFY IT TO PRODUCE PRIME NUMBERS INSTEAD OF SQAURES

public class SequenceTester {
    public static void main(String[] args){
        Squares sq = new Squares();
        for(int i=0;i<20;i++)
            System.out.println(sq.next());
    }
   
}
class Squares implements Sequence{
       private int n;

   public int next()
   {
      n++;
      return n * n;
   }

}

JAVA OOP thank you

Explanation / Answer

public class SequenceTester {
    public static void main(String[] args){
        Squares sq = new Squares();
        for(int i=0;i<20;i++)
            System.out.println(sq.next());
    }
   
}
class PrimeSequence implements Sequence{
       private int n;

   public int next()
   {
      n++;

for(int i=1;i<n;i++){
if((n%i) == 1){
return n;
}

   }

}

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