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
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
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
The output I need to get will be like this example output
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started