This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to create Java 3D Array Object ?

 
priyanka kulathilaka
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 3 separate objects. like GSMTable,SMSTable,GPRSTable.
Those are include 2 fields called srDate,numberOfSR.
now i need to get them to 3D array object because i need to return it for my jqPlot line chart
this is my requirement

[[gsmTable.srDate][gsmTable.noOfSR],[smsTable.srDate][smsTable.noOfSR],[gprsTable.srDate][gprsTable.noOfSR]]


i wrote my own code like below.but i'm unable to complete it.

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there an association between 1 GMSTable, 1 SMSTable, and 1 GPRSTable? If so, then you don't want a 3D array. You want to define a class that has those 3 fields as member variables.
 
priyanka kulathilaka
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:Is there an association between 1 GMSTable, 1 SMSTable, and 1 GPRSTable? If so, then you don't want a 3D array. You want to define a class that has those 3 fields as member variables.


thanks for the comment.but those are not a associated objects.
then how to get that array ?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What type of object will be stored at:

[0][0][0]
[0][0][1]
[0][1][0]
[1][0][1]
[1][1][1]

?

It's really not clear to me what the dimensions of your array represent, or how the various XyzTable classes relate to it.
 
priyanka kulathilaka
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:What type of object will be stored at:

[0][0][0]
[0][0][1]
[0][1][0]
[1][0][1]
[1][1][1]

?

It's really not clear to me what the dimensions of your array represent, or how the various XyzTable classes relate to it.



my gsmArray=[[2012-11-05,05],[2012-11-06,08],[2012-11-07,10],[2012-11-08,14],[2012-11-08,09]]
my smsArray=[[2012-11-05,02],[2012-11-06,03],[2012-11-07,04],[2012-11-08,04],[2012-11-08,03]]
my gprsArray=[[2012-11-05,04],[2012-11-06,07],[2012-11-07,08],[2012-11-08,04],[2012-11-08,07]]

I need to merge gsmArray,smsArray,gprsArray as 3D Array
then my expect array should be

[[2012-11-05,05],[2012-11-06,08],[2012-11-07,10],[2012-11-08,14],[2012-11-08,09],[2012-11-05,02],[2012-11-06,03],[2012-11-07,04],[2012-11-08,04],[2012-11-08,03],[2012-11-05,04],[2012-11-06,07],[2012-11-07,08],[2012-11-08,04],[2012-11-08,07]]
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
priyanka kulathilaka wrote:
my gsmArray=[[2012-11-05,05],[2012-11-06,08],[2012-11-07,10],[2012-11-08,14],[2012-11-08,09]]
my smsArray=[[2012-11-05,02],[2012-11-06,03],[2012-11-07,04],[2012-11-08,04],[2012-11-08,03]]
my gprsArray=[[2012-11-05,04],[2012-11-06,07],[2012-11-07,08],[2012-11-08,04],[2012-11-08,07]]


It looks like you need to learn to use classes and objects.

If one element of an xyzArray is itself an array with, what I assume is a Date and an Integer, then you should instead define a class that contains a Date and Integer (or Date and int, or whatever those values are), and name that class something meaningful and descriptive. Then the xyzArrays would be 1D arrays with each element being an object of that class you define.


I need to merge gsmArray,smsArray,gprsArray as 3D Array
then my expect array should be

[[2012-11-05,05],[2012-11-06,08],[2012-11-07,10],[2012-11-08,14],[2012-11-08,09],[2012-11-05,02],[2012-11-06,03],[2012-11-07,04],[2012-11-08,04],[2012-11-08,03],[2012-11-05,04],[2012-11-06,07],[2012-11-07,08],[2012-11-08,04],[2012-11-08,07]]


That doesn't look like a 3D array. That looks like a 2D array that's just a concatenation of your other 2D arrays.

You haven't described what the values represent or how the relate to each other, and your examples are not consistent with what you say you want, so I don't know how to help you any further.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic