-
simple error on code??
Hi Its me again, trying still to do this array getting the following error
--------------------Configuration: j2sdk1.4.0_01 <Default>--------------------
\java\Sparr2.java:43: cannot resolve symbol
symbol : method airport (java.lang.String)
location: class Sparr2
String[] info = airport(KeyboardInput.readLine());
^
1 error
Process completed.
Here is my code:
Code:
import java.io.*;
class Sparr2
{ // Airport Flt No Destination Flt time
static String[][][] tdi = { {{"Paris", "418", "Rome", "55"},
{"Liverpool", "121", "Copenhagen", "35"},
{"Liverpool", "418", "Paris", "50"},
{"Liverpool", "553", "Frankfurt", "55"},
{"Frankfurt", "553", "Budapest", "50"},
{"Amsterdam", "121", "Madrid", "65"},
{"Amsterdam", "418", "Paris", "35"},
{"Madrid", "121", "Stockholm", "90"},
{"Budapest", "553", "Warsaw", "30"},
{"Copenhagen","121", "Amsterdam", "35"},
{"Rome", "418", "Amsterdam"," 60"}}};
public static String[] getFlights(String airport)
{
java.awt.List result = new java.awt.List();
for(int i=0; i < tdi.length; i++)
{ for(int j=0; j < tdi[i].length; j++)
{ for(int k=0; k < tdi[i][j].length; k++)
{ if ( tdi[i][j][k].equals(airport) )
{ result.add(tdi[i][j][1]);}
}
}
} return result.getItems();
}
public static void main(String args[]) throws IOException
{
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader KeyboardInput = new BufferedReader(input);
System.out.println("Enter name of airport");
String[] info = airport(KeyboardInput.readLine());
if(info==null)
System.out.println("No airport of that name");
else
System.out.println(tdi [0][0]+" Flight numbers "+tdi[0][1]);
// if liverpool is entered
// should print out Liverpool flight numbers 121,418 ,553
// 418
// 553
}
}
I don't know if I done code right to print out airport flight times
but i am still trying
thanks
lindsey
-
Do you have a method named "airport"? The compiler is looking for that method. Perhaps you meant to use the method "getFlights".
String[] info = getFlights(KeyboardInput.readLine());
-
Hi Phenix
Did what you said, but I still am printing out
[Ljava.lang.String;a4ad40d Flight numbers Ljava.lang.String;a4ad40d instead of
liverpool fights 121
418
553
Could you help please
Lindsey
-
1 Attachment(s)
Ouch. I lost all my comments when I tried to upload a .java file.
The highlights are the following:
[Ljava.lang.String means the output is a 1D String array
When you run my code, you'll see that tdi is [[[ a 3D string array.
System.out.println wants a string not a string array.
I don't think your code needs 3D arrays yet.
tdi[0][0] is a 1D String array {"Paris", "418", "Rome", "55"}.
Finally, ask for anAirport and loop over info[]
-
This is a misuse of arrays.