Results 1 to 5 of 5

Thread: simple error on code??

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Location
    Kentl
    Posts
    7

    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

  2. #2
    Addicted Member Phenix's Avatar
    Join Date
    Sep 2002
    Location
    Near A Cube
    Posts
    228
    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());

  3. #3
    New Member
    Join Date
    Oct 2002
    Location
    liverpool
    Posts
    9
    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

  4. #4
    Addicted Member Phenix's Avatar
    Join Date
    Sep 2002
    Location
    Near A Cube
    Posts
    228
    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[]
    Attached Files Attached Files

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    This is a misuse of arrays.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width