File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes I'm lost on how to do and call 3d array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I Watch "I New topic
Author

I'm lost on how to do and call 3d array

Lindsey Ship
Greenhorn

Joined: Feb 07, 2003
Posts: 19
Hi I am in a real mess, trying to do a 3d array. I am only new to java so forgive me
If this looks messy.I do not know how to call the methods ect.
what i have to sort out is!
if i enter a airport name it will display the flight No's:
if i enter flight number it will display destination and flight time
I was trying to ref the name of airports by int so that I can call from the rest of the
array. Can any one put me on the right track please!

Here is my horrible attempt
Lindsey Ship
Greenhorn

Joined: Feb 07, 2003
Posts: 19
Hi iam sorry if i ask to much, I really do want to learn, so if anyone can give a tutorial site on 3d arrays. I will check it out as all the books i have read don't give examples on 3d.
Sorry if i have come across a fool with my code as i know it is messed up and most proberly wrong in all aspects
thanks if you can help, in case i am in bed when you answer as it geting late now in th UK.
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2850
    
  11

OK, first "Don't Panic!" That's the best advice ever to come out of The Hitchhiker's Guide to the Galaxy. Everyone has to begin somewhere. Relax and don't worry so much about seeming a "fool".
Now with that said, yes, this is a horrible attempt. You have aps, which is clearly a one-dimensional array (notice the single set of brackets in String []), but you're trying to apply multiple indices to it: aps[i][0]. Also, i is a static variable set outside the method, which, as you will find as you gain familiarity with programming, is something you really don't want to do.
Let's just take your first goal: given the name of an airport you want to return the flights for that airport. Will there be more than one flight per airport? Probably. Will there be the same number of flights per airport? Probably not. What I'm getting at is that I don't think you want to use a multi-dimensional array at all. How about arrays stored in a hash table? Is that beyond the scope of this assignment?
Try this:

Of course, that's just off the top of my head, and I haven't even compiled it, but it should work more or less.
A couple final closing points about multi-dimensional arrays (for anyone left reading):
1. Multi-dimensional arrays are usually only theoretically useful. In real life, arrays or other collections of objects are more common.
2. You should make sure you understand one-dimensional arrays, before trying to wrap your mind around 2D, 3D, and nD.
Lindsey Ship
Greenhorn

Joined: Feb 07, 2003
Posts: 19
Thanks Greg for your advise
I am now trying with a 2d array, got my first part working calling the airport Liverpool it now displays all 3 flights. Used a counter which I read about in a book.I am stuck on second bit, will try and sort it out but I am totally confused. You will see what I mean if I can not sort it . I hope you guys won't object me coming back with a new post.
Thanks again all the little problems seem major when you are just in your 1st stage of learning.
Oh a special thanks to you guys who run this site for beginners, as other site's mock us for asking. What must be silly questions to them.
Wish I could send a thank you card to the ranch for all the Staff and you guys and girls who give up your time to help the likes of myself.
Sorry for going on to much
Take care every one xxxx
Lindsey
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I'm lost on how to do and call 3d array