Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

variable issue. Trying to create random coordinate doubles and store tham in a 2D array.

Greenhorn
Posts: 2
Hi All,

This is my first post. I have limited experience in MATLAB and have taken on a Java subject for uni. I have a non graded task for uni in which there is an additional component for those wishing to challenge themselves. After a week I realise I need help.

"Week 2
The practical code will expand over the next few practicals so that it holds a 2D raster surface as values in an array of arrays (2D array). However, we could instead store the x/y coordinates and attributes of vector points in our array. Try taking a copy of this week practical and adapting it so that rather than storing an array of doubles, it stores an array of Point objects, each containing an x and y value. Try setting and getting back a couple of x values from within the array. (Make sure you take a copy of your practical code, as we'll work with the double-array version next week). You'll need to make a third 'Point' class, as we saw in the lecture." It is from the University of Leeds if you want to confirm that it isn't an assignment.

I have tried extending it further to make the coordinates random and am having problems. Storage.java holds the data. Point.java allows the stored data to be represented as coordinate pairs. I am having problem running it. Any direction or guidance would be greatly appreciated.

I originally made the code successfully by originally defining the array values using the method shown immediately below (in the Storage.java file).

My final (yet erroneous) code has tried to replace this manual use of defining values in a loop where each coordinate for the respective [x,y] position in the array is a random number. It is presented below. The ERROR encountered states that in the Analyst.class the variables i and j can not be found, however they are present in the for loop, no? The process has worked for me in more simple code in the past.

Steve

Jeff Verdegan
Bartender
Posts: 6109
6
Hi Stephen, and welcome to the Ranch!

In the future, when posting code, please UseCodeTags(←click) so that your code will be easier to read. I've added them for you this time.

I am having problem running it.
Note that ItDoesntWorkIsUseless(←click). We need you to TellTheDetails(←click) about what specific trouble you're having. Thanks!

Campbell Ritchie
Sheriff
Posts: 50744
83
Welcome again

I hope nobody is trying to teach you there is such a thing as a 2D array, because there isn’t. What you have is an array of arrays.