• 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

where am i calling method in wrong ??

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi every one, yet again
First I must state I must use this type of array
The program works for the first stage ie. when i type a name of a airport in. It displays all the flights.(great that took me 4 nights to work out)
The program then ask for a flight number.
It is supposed to display the destination and flight time.
But it is now I get array out of bounds ???
also in compiling I get this, which i thought i would need to display fight time.

Error message =
\java\AirLine1.java:119: cannot resolve symbol
symbol : variable k
location: class AirLine
System.out.print(" Destination " +info1[ j ] +" Flight Time"+ info1[k]+"\n " );
^
1 error
Process completed.

Can any one tell me where I am going wrong in my code please. I have posted the full code so far but I can't get pass this problem.

Thanks if you can advise a learner to java
Lindsey
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am just going to let you know what I see, I don't know if this willl answer your original question:

This code says you have three loops, one inside the other. You are not placing curly brackets after each 'for' so the code is hard to read. Inside of all these loops you only use 'j'. What are the other loops suppose to be doing for you? Except creating lots of confusion?
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Where is 'k' coming from? I don't see it declared anywhere.
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It looks like you are trying to load 3d data into a 2d array.
[ February 13, 2003: Message edited by: William Barnes ]
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You can't use this test for a multidiamentional array. Well you can but it will tell you to total of all the elements. So you can't use it this way:


for(int i = 0; i < tdi.length; i++)


and assume that 'i' will stay in bounds for the first diamention of the array.
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I have a suggestion. You don't see to know how to use multi-diamentional arrays. So trying to write code which will search though them is going to be a bit difficult. (Actually impossible.)
I would suggest that you load the array and print it out, in the exact same format which it is loaded - a table.
When you are able to do that than you will understand how the data is stored, and how to access it. Only than do you want to start thinking about how to search through it.
 
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 for your advise, as you can guess I am still lost with java , if i take out the j and k which i tried before i posted will i be able to call the data then or am i going down the wrong path. As my first method works great, do i have to do 2 more methods one for calling destination and one for time.
oh am i laying my code out in the right order the way i placing methods and the rest out.
thanks again
Lindsey
 
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 again I have took out j and k
ist method works okay ie.
if I enter Liverpool it displays all flights
Then I ask for a flight number ie 553 I
expected it to print out "Frankfurt" as that
flight leaves liverpool to "Frankfurt"
but
what the 2nd method is doing is printing out
all destinations with 553.
Can you give us a tip on this please
Lindsey
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All right, let's back up here a minute and see if we can try to get your requirements straight. From what I can see from the code you've given this is what is supposed to happen:
  • You start with a given set of data about flights: Airport, Flight#, Destination, Flight Time. This data should be contained in an array of some sort (more on this below)
  • User is prompted for a name of an airport
  • System displays a list of flight numbers originating from that airport or an error message if the airport could not be found
  • User is prompted for a flight number
  • System displays the destination and the flight time or an error message if the flight number could not be found.


  • Is this correct? Also, you have been asking about three dimensional arrays. Your code, however, only has a 2-dimensional array. How exactly should the data be organized?
     
    William Barnes
    Ranch Hand
    Posts: 1067
    2
    IntelliJ IDE Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    > am i laying my code out in the right order the way i placing methods and the rest out
    That is fine.
    Please ignore my earlyer post about 3d arrays. I was confused.
    > what the 2nd method is doing is printing out all destinations with 553.
    Please post the latest version of this method.
     
    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 Junilu
    Thanks for your help, you was spot on with what my code has to do.
    But after a full week of late nights I relised the layout of what they want is wrong.I am not suprised if you heard my screams their in the USA.
    I have made a good start on my new version about a 3rd way through it. But bang I have Hit a brick wall again. Now i feel i can not come back to you guys as you have already been decent to give up your time so far.
    Thanks again and I wish all of you on your ranch
    the best of luck and good health
    Lindsey
     
    mister krabs
    Posts: 13974
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by Lindsey Ship:
    Now i feel i can not come back to you guys as you have already been decent to give up your time so far.

    Don't be silly! Most of us live to solve other people's problems. (That way we can avoid working on our own. )
     
    William Barnes
    Ranch Hand
    Posts: 1067
    2
    IntelliJ IDE Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    > Now i feel i can not come back to you guys as you have already been decent to give up your time so far.
    Don't be silly. We love criticizing your code, ... I mean helping you out. We don't show up unless we have time. So please post back with the new code (but start a new thread). Thanks.
     
    A day job? In an office? My worst nightmare! Comfort me tiny ad!
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic