Question: Write a full program containing a method countValidNumbers according to the following description. Please review this information carefully, including the grading rubric at the end;
Write a full program containing a method countValidNumbers
according to the following description. Please review this
information carefully, including the grading rubric at the
end; take notes as you plan your program to make sure
you cover all of the requirements:
Write a method that counts valid numbers entered by the user.
The method takes a Scanner connected to the console plus
two ints as its parameters only numbers that are evenly
divisible by a number between those two ints, inclusive, are
considered valid, so if the ints are and then numbers that
are evenly divisible by or are considered valid
numbers and should be counted. Numbers that are not evenly
divisible by any of the indicated numbers are not counted.
This is a conditional cumulative sum problem. Be careful: if
a number is evenly divisible by more than one of the ints in
the parameter range, you must only count that valid number once.
The method must reject second andor third parameter values
that are by throwing an IllegalArgumentException.
The two integers given to the method may be given in either
order, the smaller first or the larger. You may want to write
code inside the method to check their order so that you always
process the integers from the smaller to the larger. The two
integers may be the same.
Note that if one of the parameter numbers has the value then
any number that the user enters will be valid.
After the method counts valid numbers that the user enters it
must return that count. The user signals that all numbers have
been entered by typing anything that is not a number. Use
Scanner methods to check whether the next thing to be
read is in fact a number, and stop counting if it is not. Be sure
to "consume" that nonnumber by reading it as a "word" so that
future calls of countValidNumbers will be able to work. Note
that the user may type each number on a separate line or type
some or all of the numbers on the same line separated by
white space each number is a Scanner "token"
The method must tell the user what it does and prompt them
for input related to the numeric parameters it is given. The
method must tell the user that when they enter something that
is not a number the program will stop accepting numbers and
return the count of valid user numbers that it has seen so far.
The ending nonnumber must not be included in the count, it
is a SENTINEL value for the method.
The program must contain both pseudocode for the method as
well as pre and postcondition comments regarding the method.
Note: pseudocode is not inline comments inside the method,
but rather a block of comments before the method that explains
how the method will implement its requirements conceptually, not
with details about the implementation so the pseudocode would
NOT look like Java statements but rather what logic and
information it will use in its implementation. It may include
the types of statements used in the method such as loops or
decisionmaking, but only the general nature of those statements
and the tests that such statements use, not their specific content.
See pages and in the textbook.
Pre and postcondition comments must follow the pseudocode and
precede the method. See pages and in the textbook.
The method may optionally contain inline comments as well.
Note that it is permissible to have additional "helper" methods
that make writing the required method easier. If you write such
methods you must also write pseudocode and pre and post
condition comments for those methods.
The program containing this method must calltest the method
in main three times for testing purposes as follows:
Test : the numbers are and in that order
Test : the numbers are and in that order
Test : at least one of the numbers is throws an exception
At least one of the numbers entered for the first test should
not be divisible by any of or ; for the second test
the first entered number should be invalid not divisible by
or like and the second entered "number" should be
some random nonnumber, like STOP, so that the returned count
of valid user numbers would be The third test should throw
the required exception because at least one of the int parameter
values is
Example:
If the method is called like this:
int count countValidNumbersconsole;
and the user types the following lines:
endOfInput
then the method will return a count of valid numbers,
divisible by divisible by and divisible by
and only counted once the other numbers are primes,
so and do not divide them evenly.
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
