CSCI 202 Homework 8

Rules of submission

This assignment must be submitted to the Moodle submission page for Homework 8 by 11:00 PM on Friday, 22 March.

Your submission must contain two classes Point1080 and ManyPoints that contain the methods described below.

Getting started

In Lab 9 you wrote a program for a class Point1080, and in Lab 10 you wrote two methods randomPoints and averagePoint in a class ManyPoints that used arrays of Point1080 objects.

If you don’t have Point1080, randomPoints and averagePoint written, you need to do that now. Be sure they are all in the edu.unca.cs.csci202 package.

The task

Add one more method, manySmallSquares, which receives a positive integer parameter n and returns an n×2 array of Point1080 objects which represents n small squares, randomly distibuted across the 1920×1080 grid and each of size 10

Let’s say your method is called with the following statement
    littleBoxes = manySmallSquares(100) ;
This should return a 100×2 array. The i’th box is represented by littleBoxes[i][0] and littleBoxes[i][1]. littleBoxes[i][0] should be the vertex of the upper-left corner of the box, and littleBoxes[i][1] should be the vertex of the lower-right corner. Each box is 10×10. This means that the x and y co-ordinates of the lower-right corner are 10 more than those of the upper-left corner. This restriction is certainly artificial, but it does make the programming easier.

So why not just call randomPoints and then add 10 to the x and y co-ordinates of each point of the returned array? The only problem is that, after the addition of 10, some of those points would fall off the grid. However, it wouldn’t be hard to change the range of the random variables.