Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You will be writing a program that takes two whole number ( without a decimal point ) between 0 ( inclusive ) and 1 0
You will be writing a program that takes two whole number without a decimal point between inclusive and inclusive on the command line and find and prints out all prime numbers between those numbers. For instance, if your program is invoked with and your program will print
You must:
name your main class "PrimeFinder"
put all your programclasses in a package called "prime".
check for errors in command line arguments and handle it properly.
Example Run of the program
The red color indicates the program's output. The dollar sign $ indicates your command line prompt and what follows is what the user types on the command line terminal
Example positive no error:
$ java cp prime.PrimeFinder
Example positive no error:
$ java cp prime.PrimeFinder
Example positive no error:
$ java cp prime.PrimeFinder
Example Negative bad input:
$ java cp prime.PrimeFinder
Error: Max must not be smaller than Min
Example Negative bad input:
$ java cp prime.PrimeFinder abc
Error: Invalid arguments
Example Negative bad input:
$ java cp prime.PrimeFinder
Error: Min out of range. Minimum must not be smaller than
Example Negative bad input:
$ java cp prime.PrimeFinder
Error: Max out of range. Maximum must not be greater than
Example Negative bad input:
$ java cp prime.PrimeFinder
Error: Min and Max must be whole numbers.
Example Negative missing an argument:
$ java cp prime.PrimeFinder
Usage: PrimeFinder
Additional Instructions and Hints
You must validate the command line arguments passed in by the users. The examples above cover some of the error cases that you need to handle but there may be more. Big part of your grade will be about error detection and handling.
Command line arguments appear in your main method's argument as an array of Strings String You can check the number of command line arguments which is equal to the length of this array and read each of them as a String, and then perform validations on them or convert them to numbers or integers. You can use the method Long.ParseLongString s to convert a String to a long number.
A number is a prime if and only if it's divisible by and itself. To confirm that a number is prime, you need to make sure it is not divisible by any prime numbers that are smaller than or equal to the quare root of that number. For instance, to recognize if is prime, you keep dividing it by all prime numbers that are smaller than or equal to the square root of ie which are and If the number is divisible by any of those primes, then it is not a prime. To test for primality, you must make sure it's not divisible by divide it by any prime smaller than or equal to the square root of ie and
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