aspose file tools*
The moose likes Java in General and the fly likes variable issue. Trying to create random coordinate doubles and store tham in a 2D array. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "variable issue. Trying to create random coordinate doubles and store tham in a 2D array. " Watch "variable issue. Trying to create random coordinate doubles and store tham in a 2D array. " New topic
Author

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

Stephen Bradshaw
Greenhorn

Joined: Apr 28, 2013
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.



Thanks in advance,
Steve










Jeff Verdegan
Bartender

Joined: Jan 03, 2004
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.

Regarding your problem:
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

Joined: Oct 13, 2005
Posts: 39436
    
  28
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.
Stephen Bradshaw
Greenhorn

Joined: Apr 28, 2013
Posts: 2
Hi guys,
Thanks for the welcome.
Yes, array of arrays. That is a mistake on my part.

I have taken the advice and "corrected" the problem.

Regards,
Steve
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: variable issue. Trying to create random coordinate doubles and store tham in a 2D array.