Question: [ Utilities ] Implement the methods in Primes.java. import java.util. * ; import java.io . * ; class Primes { / * in this assignment,
Utilities Implement the methods in Primes.java.
import java.util.;
import java.io;
class Primes
in this assignment, we will only work with the first primes
static int NUMPRIMES ;
the square of the value of the largest prime number used in this
assignment
static int SKY ;
the values of the first NUMPRIMES prime numbers
static int primes new intNUMPRIMES;
load the first NUMPRIMES prime numbers from the file "primes.txt
into the static array 'primes'. This method must also
initialize the SKY static variable.
public static void loadPrimes
To be completed
loadPrimes method
return true if and only if its input is one of the first NUMPRIMES
prime numbers.
public static boolean isPrimeint n
To be completed
return false; Delete this line in your submission
isPrime method
given an integer, return a element array containing its two
prime factors if the input is the product of two primes with
the smallest prime in the first array location; otherwise
return an empty element array.
public static int factorint n
To be completed
return null; Delete this line in your submission
factor method
return the greatest common divisor of the two input integers,
which are assumed to be positive. The implementation of this
method must be iterative. No recursion allowed! You are also
not allowed to use any gcd method in any of the Java API
classes. You may not use any helper methods. You must implement
this method from first principles.
public static int gcdint mint n
To be completed
return ; Delete this line in your submission
gcd method
return true if and only if alpha is a primitive root modulo q
public static boolean isPrimitiveRootint alpha, int q
To be completed
return false; Delete this line in your submission
isPrimitiveRoot method
return the largest primitive root of q or if q does not have
a primitive root
public static int pickAlphaint q
To be completed
return ; Delete this line in your submission
pickAlpha method
This method is used for testing.
Do NOT modify it
public static void mainString args
if argslength
loadPrimes;
if argsequalsload
System.out.printlnTesting loadPrimes;
loadPrimes;
System.out.printlnprimes;
System.out.printlnprimesNUMPRIMES;
System.out.printlnSKY;
else if argsequalsisPrime
forint i ; i ; i
System.out.printlnisPrimei;
else if argsequalsfactor
forint i ; i ; i
int result factori;
if resultlength
System.out.formatd is the product of d and d
i result result;
else if argsequalsgcd
forint i ; i ; i
forint j ; j ; j
System.out.printlngcd i j
gcdij;
else if argsequalsprimRoot
forint i ; i ; i
int n primesi;
System.out.printn : ;
forint j ; j n; j
if isPrimitiveRootjn
System.out.print j ;
System.out.println;
else if argsequalspickAlpha
forint i ; i ; i
int q primesi;
System.out.printlnq : pickAlphaq;
Primes class
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
