Write a method that takes two arguments: an int and
a Numbers object. The int specifies how many
numbers you are to add up and the Numbers object has a
method nextNumber that you can call to get one number at a
time.
Write a method that takes two arguments: an int and
a Numbers object. The int specifies how many
numbers to pull from Numbers. The methods should return the
average all the numbers pulled. (Note: if n is zero then there are no
numbers to average and this method should return the
special double value NaN which you will get if
you divide a double. by zero.)
Write a method that takes two arguments: an int and
a Numbers object. The int specifies how many
numbers to pull from Numbers. The methods should return the
average of only the even numbers pulled. (Note: if there are no even
numbers to average this method should return the
special double value NaN which you will get if
you divide a double. by zero.)
Write a method that takes two arguments: an int and
a Numbers object. The method should return the average of the
first n even numbers pulled from the Numbers object where n
is the first argument.
Write a method to determine whether any of the numbers you draw from
the Numbers object are greater than a given limit. It should
take three arguments: an int specifying how many numbers to
draw, an int specifying the limit, and a Numbers
object from which to draw the numbers with the nextNumber
method.
Write a method to determine whether all the numbers drawn from
the Numbers object are less than a given limit. It should
take three arguments: an int specifying the number of numbers
to draw, an int specifying the limit, and
a Numbers object from which to draw the numbers with
the nextNumber method.
Write a method that returns the first number drawn from
the Numbers object that is greater than a given limit. It
should take two arguments: an int specifying the limit, and
a Numbers object from which to draw the numbers with
the nextNumber method.
Write a method that returns the position (zero-based) of the first number
drawn from the Numbers object in a given number of tries that
is greater than a given limit. That is, if the limit was 10 and the first
few numbers were 3, 2, 13, 15, it would return 2 because the first number
greater than 10 was 13 which was at position 2. It should take three
arguments: an int specifying the number of numbers to draw,
an int specifying the limit, and a Numbers
object from which to draw the numbers with the nextNumber
method. It should return -1 if no number is found that is bigger than the
limit.
Write a method that takes two arguments: an int and
a Numbers object. The int specifies how many
numbers you are to draw from the Numbers object via its
method nextNumber. The method should return how many of
those n numbers are odd.
Write a method that takes three arguments: an int n,
an int m, and a Numbers object. The method will
return the sum of a bunch of products: it should draw n
numbers from the Numbers object and for each of these numbers
multiply it by each of m numbers drawn from
the Numbers object, totalling up all the n times m products.
When it is done, it should return the total.
All the methods in this test take an argument of the
type Numbers. This is a class that has only one method you need
to use: nextNumber which takes no arguments and returns a
random number. The methods you will write will use the Numbers
object as a source of numbers that the methods will then do things with like
summing them up or averaging them, etc.