Prime numbers. Write a program that prompts the user for an integer and then prints out all prime numbers up to that integer. For example, when the user enters 20, the program should print

2
3
5
7
11
13
17
19

Recall that a number is a prime number if it is not divisible by any number except 1 and itself.

Supply a class PrimeGenerator with a method nextPrime.

Complete the following files:

PrimeGenerator.java

/** This class generates all prime numbers. */ public class PrimeGenerator { . . . public PrimeGenerator() { . . . } /** Calculates the next prime number. @return the next prime number */ public int nextPrime() { . . . } }

PrimePrinter.java

Use the following file:

PrimeGeneratorTester.java

public class PrimeGeneratorTester
{
   public static void main(String[] args)
   {
      PrimeGenerator generator = new PrimeGenerator();
      System.out.println(generator.nextPrime()); 
      System.out.println("Expected: " + 2);
      System.out.println(generator.nextPrime());  
      System.out.println("Expected: " + 3);
      System.out.println(generator.nextPrime());  
      System.out.println("Expected: " + 5);
      System.out.println(generator.nextPrime());  
      System.out.println("Expected: " + 7);
      System.out.println(generator.nextPrime());  
      System.out.println("Expected: " + 11);
      for (int i = 6; i <= 9999; i++)
         generator.nextPrime();
      System.out.println(generator.nextPrime());  
      System.out.println("Expected: " + 104729); // the ten thousandth prime
   }
}