Results 1 to 11 of 11
Thread: Need some help
- 04-01-2009, 10:58 AM #1
Member
- Join Date
- Apr 2009
- Posts
- 4
- Rep Power
- 0
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
any suggestion will help me:)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); } }Last edited by 7ussain; 04-01-2009 at 11:02 AM.
- 04-01-2009, 11:22 AM #2
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
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
- 04-01-2009, 11:22 AM #3
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 8
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.
- 04-01-2009, 11:44 AM #4
Member
- Join Date
- Apr 2009
- Posts
- 4
- Rep Power
- 0
I want to get JED
but I can't
- 04-01-2009, 11:45 AM #5
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 8
Okay, that doesn't help us anymore than the rest does.
IOW, what is your actual problem?
- 04-01-2009, 11:50 AM #6
Member
- Join Date
- Apr 2009
- Posts
- 4
- Rep Power
- 0
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
- 04-01-2009, 12:06 PM #7
Member
- Join Date
- Apr 2009
- Posts
- 5
- Rep Power
- 0
it would be easier if u use collection rather than string
- 04-01-2009, 12:08 PM #8
Member
- Join Date
- Apr 2009
- Posts
- 4
- Rep Power
- 0
^^
can you expline how?
- 04-01-2009, 08:57 PM #9
Member
- Join Date
- Apr 2009
- Posts
- 5
- Rep Power
- 0
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.
- 04-02-2009, 03:36 AM #10
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
BISWAJIT KUMAR BABU
how to handle letter case in the key of the map?
- 04-02-2009, 08:32 AM #11
Member
- Join Date
- Apr 2009
- Posts
- 5
- Rep Power
- 0


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks