What I want to do is to take a 2d int array and use it to create a Matrix (a class I will be defining) which will effectively wrap all the values of the 2d array together so that I can perform matrix multiplication for coordinate translation. I am rather confused as to how I would do this however. My main problem that I can't figure out is that how can I create the Matrix object so that I can still access specific value at a row and column location (since it won't be an 2d array anymore I can't go something like 'matrix[i][j]')? Anybody have any ideas, or am I approaching this completely wrong?

Recommended Answers

All 3 Replies

it won't be an 2d array anymore I can't go something like 'matrix[i][j]')? Anybody have any ideas, or am I approaching this completely wrong?

While in other languages such as C# or C++ you have operator overloading, there's no such feature in Java.
Your best bet is creating a method for it, e.g. get(int row, int column).
Also take a look on the Internet, Google a bit, there are no doubt examples of Matrix classes in Java.

I figured that, but I guess I'm just trying to figure out how to create the Matrix object so that I can store the values in row, column way. Right now, I'm creating a Matrix object to take a 2d array of int. So I could create a 2d int array and fill it with the values, then put that array in a new Matrix object, but then how would I write the get method?

but then how would I write the get method?

Have you seriously spent time using a search engine?
Under 1 minute you could've answered your own question by just Googling.
(Notice that is faster than waiting for this reply)

Anyway, here is an example:

public int get(int row, int column)
{
    return matrix[row][column];
}

Look here and here for more info.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.