### Solution to problem 7.11

In PrimeGenerator.java:

```public class PrimeGenerator {
private int lastPrime = 1;
private final int MAX_PRIME;

public PrimeGenerator(int maxPrime) {
MAX_PRIME = maxPrime;
}

public int next() {
lastPrime++;
int divisor = 2;

// The expression after the logical AND is
// a way of reducing the number of operations
// required to determine if a number can be a
// prime.
while (lastPrime <= MAX_PRIME &&
divisor*divisor <= lastPrime) {
if (lastPrime == divisor) { // prime!
return lastPrime;
} else if (lastPrime % divisor == 0) {
// not prime
lastPrime++;
divisor = 2;
} else {
// try the next highest divisor
divisor++;
}
}

if (lastPrime > MAX_PRIME) return -1;
else return lastPrime;
}
}
```

In Main.java:

```public class Main {
public static void main(String[] args) {
PrimeGenerator pg = new PrimeGenerator(2000);
// Print first 50 primes, five primes per line
for (int line = 0; line < 10; line++) {
for (int prime = 0; prime < 5; prime++) {
int n = pg.next();
if (n != -1)
System.out.print(n + " ");
} System.out.println();
}

}
}
```