Results 1 to 11 of 11

Thread: Need some help

  1. #1
    7ussain is offline Member
    Join Date
    Apr 2009
    Posts
    4
    Rep Power
    0

    Default Need some help

    Hi

    this is the question:
    In airlines reservation systems "dan jeddah" command is used to get the airport code for Jeddah city.
    Design and implement a java code that simulate the "dan" command.
    Use the following file as a dataset:

    I can't put the link:confused:

    Use contains method in String class to look up the city and return the city code.
    e.g. dan Jeddah returns JED


    and I wrote this code
    Java Code:
    import java.io.*;
    import java.util.*;
    public class Dan{
    	public static void main (String[] args){
    	
    		
    	Scanner input= null;
    	try{
    		input = new Scanner(new File("C:\\Users\\Lost Spirit\\Desktop\\iata-airport-codes.txt"));
    	}	
    		catch(FileNotFoundException e){
    			System.out.println("not found the file");
    			System.exit(0);
    		}
    		
    	Scanner h= new Scanner(System.in);
    		String we= h.nextLine();
    		
    		String line= null, er= null;
    		int qwe;
    		while (input.hasNextLine()){
    			line= input.nextLine();
    		qwe= line.indexOf(we);
    		er= line.substring((qwe-4),(qwe-1));
    		
    		}
    		input.close();
    		System.out.println(qwe);
    		
    	}
    	
    	
    }
    any suggestion will help me:)
    Last edited by 7ussain; 04-01-2009 at 11:02 AM.

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    7

    Default

    String we should be "dan xxx" string
    String line ... i dont know the format
    but i think String line would not consist "dan"
    qwe seems always 0
    String.substring( -ve, -ve) should throw IndexOutOfBoundsException

    also
    "jeddah" search for "Jeddah City"
    so, you need to handle case of letter

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    10

    Default

    Okay, you've shown us the assignment, and what you did, but you have not told us what compiler/errormessages you are getting nor what it is (or is not) doing that it should (or should not) do.

  4. #4
    7ussain is offline Member
    Join Date
    Apr 2009
    Posts
    4
    Rep Power
    0

    Default

    I want to get JED
    but I can't

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    10

    Default

    Okay, that doesn't help us anymore than the rest does.

    IOW, what is your actual problem?

  6. #6
    7ussain is offline Member
    Join Date
    Apr 2009
    Posts
    4
    Rep Power
    0

    Default

    is there any code to look up in txt file by scanner and get the first word in the line which I looked up in it

  7. #7
    Join Date
    Apr 2009
    Posts
    5
    Rep Power
    0

    Default

    it would be easier if u use collection rather than string

  8. #8
    7ussain is offline Member
    Join Date
    Apr 2009
    Posts
    4
    Rep Power
    0

    Default

    ^^
    can you expline how?

  9. #9
    Join Date
    Apr 2009
    Posts
    5
    Rep Power
    0

    Default

    hi,
    i think u can go for a collection map where u can store the name of the city and that code as a key value pair .
    if u can use this rather than the file. u can easily extract the city code by just creating a iterator.

  10. #10
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    7

    Default

    BISWAJIT KUMAR BABU
    how to handle letter case in the key of the map?

  11. #11
    Join Date
    Apr 2009
    Posts
    5
    Rep Power
    0

    Default

    hi mtyoung,
    map needs a key & value pair. the value has to be an type of object. cant we make the value we are extracting a string object.

Posting Permissions

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