Question: I am desperately in need of help writing a java program that will generate prime numbers This is my main method that will print my

I am desperately in need of help writing a java program that will generate prime numbers

This is my main method that will print my output ->

package primegeneratordemo;

import java.util.ArrayList;

import java.util.Random;

import java.util.Scanner;

public class PrimeGeneratorDemo

{

public static void main(String[] args)

{

Scanner cin = new Scanner(System.in);

System.out.print("Enter a positive integer -> ");

int n = cin.nextInt();

PrimeGenerator primeSeq = new PrimeGenerator(n,'E');

System.out.printf("Is %d a prime number? %b%n",n,primeSeq.isPrime(n));

System.out.printf("Prime numbers in [1,%d] are %s.%n",n,primeSeq);

System.out.printf("The largest prime number in [1,%d] is %d.%n",n,primeSeq.getMax());

ArrayList primes = primeSeq.generate(n);

System.out.printf("The number of prime numbers in [1,%d] is %d.%n",n,primes.size());

//Add code to generate a random prime in [2,n] and the table shown on handout:

}

}

___________________________________________________________________________________________

This is the interface class that goes with the main ->

package primegeneratordemo;

import java.util.ArrayList;

import java.util.Random;

import java.util.Scanner;

public class PrimeGeneratorDemo

{

public static void main(String[] args)

{

Scanner cin = new Scanner(System.in);

System.out.print("Enter a positive integer -> ");

int n = cin.nextInt();

PrimeGenerator primeSeq = new PrimeGenerator(n,'E');

System.out.printf("Is %d a prime number? %b%n",n,primeSeq.isPrime(n));

System.out.printf("Prime numbers in [1,%d] are %s.%n",n,primeSeq);

System.out.printf("The largest prime number in [1,%d] is %d.%n",n,primeSeq.getMax());

ArrayList primes = primeSeq.generate(n);

System.out.printf("The number of prime numbers in [1,%d] is %d.%n",n,primes.size());

//Add code to generate a random prime in [2,n] and the table shown on handout:

}

}

__________________________________________________________________________________

This is the class that I started and need help completeing to get my output ->

public class PrimeGenerator //implements PrimeGeneratorAPI { public PrimeGenerator() { } public PrimeGenerator(int n, char alg) {

} private void eratosthenesSieve ( boolean [ ] seq, int n ) { seq[0] = false; seq[1] = false; seq[2] = true; for (int k = 3; k

__________________________________________________________________________________

The class I need help completing requires these methods

I am desperately in need of help writing a java program that

will generate prime numbers This is my main method that will print

my output -> package primegeneratordemo; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public

class PrimeGeneratorDemo { public static void main(String[] args) { Scanner cin =

new Scanner(System.in); System.out.print("Enter a positive integer -> "); int n = cin.nextInt();

The output I need to get will be like this example output

PrimeGenerator primeSeq = new PrimeGenerator(n,'E'); System.out.printf("Is %d a prime number? %b%n",n,primeSeq.isPrime(n)); System.out.printf("Prime

Here is a link to the full doc with all the needed info: https://drive.google.com/file/d/1nBSmXKjKavjhxxuJ19i4QKFIYhj4RX_D/view

The class will also contain two private auxiliary methods that fill the Boolean sequence using the Sieve of Eratosthenes and brute-force algorithm: Listing 6: Sieve of Eratosthenes An auxiliary method that sets seq [k] to true ifk is prime * and false f k is composite using the Eratosthenes Sieve * algorithm. * Oparam seq a boolean array that indicates whether or not * k is prime private void eratosthenesSieve (boolcan [seq) Listing 7: Sieve of Eratosthenes *An auxiliary mcthod that sets seq k] to truc if k is prime + and falsef k is composite using the brute-force algorithm * param seq a boolean array that indicates whether or not +k is prime private void naiveSieve (boolean [] seq)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!