We’re going to continue with Lab .
Oops
It really should have been called a 1920×1080 grid.
So, if needed, change your Point1080
to allow
x values from 0 to 1919 and y values
from 0 to 1079.
Task 1
Within the ManyCircle
program create a public static
method called randomPoints
that accepts a single integer parameter n and returns
an arry of Point1080
of size n.
The x and y values of the
points within that array should be randomly generated
so that they uniformally distributed over the allowable values.
(Hint: Something like 1920*Math.random()
would
generate appropriate values for x.)
No task is complete without testing, so modify your main
method to generate and print the values within a randomly generated
array.
Here is a method that might help you with the printing.
private static void printPoints(Point1080[] V) { for (Point1080 E : V) { System.out.format("(%4d,%4d)\n", E.getX(), E.getY()) ; } }
Task 2
Now write a public static
routine called
averagePoint
that returns a Point1080
and receives an array of Point1080
as its single parameter.
averagePoint
should return the average x
and y within the array.
It should also throw IllegalArgumentException
if the
input array contains no elements.
Of course you do need to test your new method.