• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Their achilles heel is the noogie! Give them noogies tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic