Results 1 to 12 of 12
Thread: Back to the math class....
 10312012, 12:46 AM #1Senior Member
 Join Date
 May 2012
 Posts
 172
 Rep Power
 5
Back to the math class....
Hello.
Basically I've made an inventory that has total spaces 2,4. 0 is a space too, so it goes like this
0,01,02,0
0,11,12,1
and so on..
Basically I have total spaces: 14 (0 is a space too)
Now the question is, if I have to work with space 2,2 or 2,3, how do I get the number of this slot? (Without a for loop)
Example:
0,01,02,0
0,11,12,1
0,21,22,2
the coordinate is 1,0  it a slot number 1.
the coordinate is 2,0  it a slot number 2.
the coordinate is 1,2  it a slot number 8.
and so on..
Any formulas?
EDIT:
Ok even loops would be fine.
EDIT 2:
Never mind, NO LOOPS.Last edited by Lionlev; 10312012 at 01:34 AM.
WARNING I am Russian so it's possible that I wont understand you correctly...
 10312012, 01:30 AM #2Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,712
 Rep Power
 14
Re: Back to the math class....
If the integer pairs represent something write a class so you can work with it.
Then, in a loop, (1) read the input, (2) create instances of the class and (3) add them to a list.
When you want to find the index of a given pair within the list it will be a simple matter to use another loop to go through the list until you have an element with the appropriate coordinates.
 10312012, 01:36 AM #3Senior Member
 Join Date
 May 2012
 Posts
 172
 Rep Power
 5
Re: Back to the math class....
I am using the loop right now, and it works, but is there a mathematical formula for that? so that would be like one line?
WARNING I am Russian so it's possible that I wont understand you correctly...
 10312012, 02:33 AM #4Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,712
 Rep Power
 14
Re: Back to the math class....
I'm not exactly sure what you want the formula to do.
Also, why no loops? If it's assignment problem it might be a good idea to post the exact wording so we can see what it means.
 10312012, 10:29 AM #5Moderator
 Join Date
 Apr 2009
 Posts
 12,921
 Rep Power
 22
Re: Back to the math class....
If these slots represent something (ie the coordinates are meaningful) then build your inventory to match, so you can get the correct slot simply by providing the coordinates.
Is this a multidimensional array?Please do not ask for code as refusal often offends.
** This space for rent **
 10312012, 01:40 PM #6Senior Member
 Join Date
 May 2012
 Posts
 172
 Rep Power
 5
Re: Back to the math class....
I've got few arraylists
Point (the slot's position) (x, y)
Rectangle (to make the slots click able)
Integer (holds all the slots ids)
Boolean (if the slot is empty)
They way my inventory works is it creates slots and adding info to each arraylist and the boolean on each one is true
Then I get the info from the server in format "id x y" I have to find that x and y in the arraylist and set boolean to false and set the Integer to the id that the server sent.WARNING I am Russian so it's possible that I wont understand you correctly...
 10312012, 04:47 PM #7Moderator
 Join Date
 Apr 2009
 Posts
 12,921
 Rep Power
 22
Re: Back to the math class....
I'm sorry, but 'x' and 'y' imply a multidimensional array to me, so unless your ArrayList is a List<List<Data>> I would argue your model is wrong.
Indeed, you seem to have a parallel array thing going on as well.Please do not ask for code as refusal often offends.
** This space for rent **
 10312012, 06:57 PM #8Senior Member
 Join Date
 May 2012
 Posts
 172
 Rep Power
 5
Re: Back to the math class....
Well it's not WRONG because it works just fine, but that is the probably long way to do it...
So I didn't actually knew that it's possible to make an array that stores multiple arguments like "boolean, integer, x,y".. I should look that upWARNING I am Russian so it's possible that I wont understand you correctly...
 10312012, 07:18 PM #9Moderator
 Join Date
 Apr 2009
 Posts
 12,921
 Rep Power
 22
Re: Back to the math class....
Well, you'd create a class that represents the data (that's a model).
Then you'd have an ArrayList<YourClass>.
But I wouldn't put the x and y in there.
I really would consider a 2 dimensional array.Please do not ask for code as refusal often offends.
** This space for rent **
 10312012, 07:28 PM #10
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,313
 Blog Entries
 7
 Rep Power
 25
Re: Back to the math class....
Can I just say that I don't understand one single syllable of this thread and I neither understand what mathematics have to do with it ...
kind regards,
JoThe only person who got everything done by Friday was Robinson Crusoe.
 10312012, 07:57 PM #11Senior Member
 Join Date
 May 2012
 Posts
 172
 Rep Power
 5
Re: Back to the math class....
I have to find the formula for this question:
The maximum of the coordinate in the table is (3;10)
How many coordinates (a) do I have to pass to reach the given coordinate (2;6)?
x=2
y=6
maxX=3
maxY=10
a = ?formula?
(a should be 17, but what is the formula to get the answer? because the give coordinate can be different)WARNING I am Russian so it's possible that I wont understand you correctly...
 10312012, 09:19 PM #12Senior Member
 Join Date
 May 2012
 Posts
 172
 Rep Power
 5
Similar Threads

Ceiling and Floor without using Math class
By teardrop3903 in forum New To JavaReplies: 1Last Post: 10132011, 05:29 AM 
help with math class and random numbers
By NestorPrime in forum New To JavaReplies: 9Last Post: 10012011, 09:57 PM 
.class to .java and back
By bluerune in forum New To JavaReplies: 8Last Post: 07052010, 03:14 AM 
Math Class
By ritwik07 in forum New To JavaReplies: 2Last Post: 09142009, 04:06 PM 
Math class question
By shendel in forum New To JavaReplies: 1Last Post: 03052009, 01:06 PM
Bookmarks