Add a new method to the Primes class called genRandPrime. It should take as input two int values: 1owerBound and upperBound. It should return a random prime number in between lowerBound(inclusive) and upperBound (exclusive) values. Test the functionality inside the main method. Implementation steps: a) Start by adding the method header. Remember to start with public statickeywords, then the return type, method name, formal parameter list in parenthesis, and open brace. The return type will be int. We will have two formal parameters, so separate those by a comma. b) Now, add the method body code that generates a random prime number in the specified range. The simplest way to do this is to just keep trying different random numbers in the range, until we get one that is a prime. So, generate a random int using: int randNum = lowerBound + gen.nextInt(upperBound); Then enter put a while loop that will keep going while randNum is not a prime number - you can use the isPrime method you developed in ex. 3 to check this. Inside the while loop body, just reassign randNum to the next random int in the range. c) After the whi le loop (after its closing brace), just add a return statement to return the value of randNum. If there is at least one prime number in the specified range, the loop will eventually terminate and a correct prime number will be returned. However, if there are no primes in the range, we will get an infinite loop. Having possibly infinite loops is a problem, as the user may not realize the code is stuck in such a loop during execution. It would be nice to make an infinite loop detector, but in general ethis is theoretically impossible. This is actually a famous problem in computer science so. undecidable problem by contradictioraaciucttirinbracs by dy Cnd can shown to be an Le an s truxi/wiki/Halting problem). d) Test the method implementation by calling it froil I ihain and outputting the value to the screen. Try different lower and upper bound values. If the program gets stuck, click on the red button by the Console window to terminate it.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Ag
1- Random Prime Generator
Add a new method to the Primes class called genRandPrime. It should take as input two
int values: 1owerBound and upperBound. It should return a random prime number in
between TowerBound (inclusive) and upperBound (exclusive) values. Test the functionality
inside the main method.
Implementation steps:
a) Start by adding the method header. Remember to start with public static keywords,
then the return type, method name, formal parameter list in parenthesis, and open brace. The
return type will be int. We will have two formal parameters, so separate those by a comma.
b) Now, add the method body code that generates a random prime number in the specified
range. The simplest way to do this is to just keep trying different random numbers in the range,
until we get one that is a prime. So, generate a random int using:
int randNum = lowerBound + gen.nextInt(upperBound);
Then enter put a while loop that will keep going while randNum is not a prime number - you
can use the isPrime method you developed in ex. 3 to check this. Inside the while loop
body, just reassign randNum to the next random int in the range.
c) After the while loop (after its closing brace), just add a return statement to return the
value of randnum. If there is at least one prime number in the specified range, the loop will
eventually terminate and a correct prime number will be returned. However, if there are no
primes in the range, we will get an infinite loop. Having possibly infinite loops is a problem, as
the user may not realize the code is stuck in such a loop during execution. It would be nice to
make an infinite loop detector, but in generalgthis is theoretically impossible. This is actually a
tl C:ad can shown to be an
s thuki/wiki/Halting problem).
famous problem in computer science sIƠ. an
undecidable problem by contradictio.raaciucttirinbrao by đcy.
Alti.
d) Test the method implementation by calling it froill rihain and outputting the value to
the screen. Try different lower and upper bound values. If the program gets stuck, click on the
red button by the Console window to terminate it.
Transcribed Image Text:Ag 1- Random Prime Generator Add a new method to the Primes class called genRandPrime. It should take as input two int values: 1owerBound and upperBound. It should return a random prime number in between TowerBound (inclusive) and upperBound (exclusive) values. Test the functionality inside the main method. Implementation steps: a) Start by adding the method header. Remember to start with public static keywords, then the return type, method name, formal parameter list in parenthesis, and open brace. The return type will be int. We will have two formal parameters, so separate those by a comma. b) Now, add the method body code that generates a random prime number in the specified range. The simplest way to do this is to just keep trying different random numbers in the range, until we get one that is a prime. So, generate a random int using: int randNum = lowerBound + gen.nextInt(upperBound); Then enter put a while loop that will keep going while randNum is not a prime number - you can use the isPrime method you developed in ex. 3 to check this. Inside the while loop body, just reassign randNum to the next random int in the range. c) After the while loop (after its closing brace), just add a return statement to return the value of randnum. If there is at least one prime number in the specified range, the loop will eventually terminate and a correct prime number will be returned. However, if there are no primes in the range, we will get an infinite loop. Having possibly infinite loops is a problem, as the user may not realize the code is stuck in such a loop during execution. It would be nice to make an infinite loop detector, but in generalgthis is theoretically impossible. This is actually a tl C:ad can shown to be an s thuki/wiki/Halting problem). famous problem in computer science sIƠ. an undecidable problem by contradictio.raaciucttirinbrao by đcy. Alti. d) Test the method implementation by calling it froill rihain and outputting the value to the screen. Try different lower and upper bound values. If the program gets stuck, click on the red button by the Console window to terminate it.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY