 All right, let's go over question eight from the compound data one workshop So for this question, you already have some sample code here So some base code so you can go ahead and copy and paste that into your processing window I've already done that and this question is good because it's got step-by-step what you need to do in order to achieve the final product so Step one we want to declare two global int arrays x and y So a few things it said global so we know we need to declare that globally And then it only says to declare it. It doesn't say to create it. We just want to make sure that their References are global so that they can be accessed from setup draw mouse release mouse press anywhere So I've got an integer array x and an integer array y So I'm just declaring them so at this point in time and both of these references are pointing to null So we want to be careful here that we're not doing any operations on them before we've created them in memory Because we'll get some null pointer exceptions Cool so question two says allocate memory to x and y for six integer values inside setup Great so that's quite easy and there's already got a comment there for us to do that So we're doing the create part so that will stop us from having null pointer exceptions So it's an integer array with six values So x is equal to a new new is our keyword that says a new place in memory a new array a new int Array with six spaces And I want the same for y Awesome, so that's all done Part three inside mouse pressed assigns to each item of array x a random value Between zero and width and to each item of array y a random value between zero and height So our mouse pressed method Oh Well, it already has comments here, so I guess we can just replace the comments with what we're doing so erase the background So the background is 255 as we see in line five, so we'll just set it to 255 again Assign a random value between zero and width to each item of x Okay, so we need a loop that will go through each item in our Array and then for each item will assign a random number And we can do it for both x and y in the same loop better doing one loop rather than two so eyes representing our index The length of x and y is the same so it doesn't matter which one we say in our loop and So each value in x being given a random value Between zero and width, so I'm going to write width plus one Because With the random method this second parameter we pass in is exclusive So it's not including that number and we want it to be between zero and width So we want it to possibly be widths So for that we need to add one and the random method returns a float so we'll cast it as an int And then we'll do the same for our y But for why it's between zero and height Great, so we've done that. I might remove those comments Great, so that's step three and then in step four it says inside mouse released Erases the background and displays lines from So in step four it says to erase the background, but it says so mouse press So I guess we'll follow what the question says rather than the comments. I'll move my background refresh Here and that makes sense because we're not drawing anything here. We're just allocating values to our array So it's more appropriate to put our background call here Erases the background and displays lines from zero zero to x zero y zero So we're drawing six lines Each line has one point starting at zero and zero in the next point at The point that is in Our x array and our y array at index zero Index one and so on so that means that we need another loop that goes through those arrays So another one here We're drawing a line. We know that the first point is always zero zero. That's not changing And the pattern here is that when our index is zero we want to draw a line from zero zero to Whatever point x zero has whatever point y zero has So it will be x I Y I Okay, so let's test out this program So Mouse press I'll hold down the mouse and I won't release it So it's not drawing anything yet. It's waiting until I release and it's drawing six lines at some random Coordinates so every time I press the mouse and release It draws some new random lines So perhaps we want to have a look at those lines Let's add some print line statements. So Let's go and print out x coordinate Filled by comma space Filled by our y coordinate and then Hopefully that looks okay. What have I done here? I didn't close Okay, so now when I press oh That was a bit silly Shouldn't be printing that so I need Close that and then add an eye Well, it's a bit messy We need to concatenate that to Okay, cool. Oh, that's a bit better All right, so our first line should be at 533 So let's have a look and see if we can find those lines. That's a bit hard to see x is 5 Y is 33 and be about here our second line 292 and 60 so 292 about here 60 about here. So that's working 65 101 65 is maybe well, that's 150 65 here is 101 height is 400 so halfway is about There 101 about here. So that's that line And then we can continue To do that we can find all of these lines every time I click. I'll get some new ones here Great, and that's how you do question 8