Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
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
Forum:
Java in General
travel agent java -- problem when i put the input prompt it does not go to the next promp
Abhradeep Banerjee
Ranch Hand
Posts: 71
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Im having problem putting the Input Prompt 1 inside the while loop
can any one help me?
Thanks
import java.io.*; import java.util.*; public class lab6Ex1 { public static void main(String[] args) { //declare var FileReader fr = null; BufferedReader br = null; String inFile = "Travel_Records.txt"; String line = ""; final String INPUT_PROMPT1 = "\nPlease select one of the following options: \n" + "1) Search flights by IC number \n" + "2) Search flights by departure date \n" + "3) Display all flights \n" + "4) Insert new record or remove old record \n" + "5) Exit program "; final String IC_PROMPT = "\n\n\nPlease enter the IC number"; final String Dept_PROMPT = "\n\n\nPlease enter the departure date in the following format" + "dd/mm/yyyy"; final String Insert_Remove_PROMPT = "\n\n\n \n" + "1) Remove Record\n" + "2) Insert Record\n" + "3) Return to previous menu\n" + "4) Exit Program"; final String Insert_Record = "Please enter new record in the following format: Serial Number|SXXXXXXXG|Name | " + "Country |MM/DD/YYYY | Time in 24 hr clock | Country | MM/DD/YYYY | Time in 24 hr clock"; final String Delete_Record = "Please enter the serial number of the record to delete"; //declare var to contain the record files int index; String NRIC; String Name; String srcCountry; String deptDate; String deptTime; String destCountry; String arrDate; String arrTime; //delare and initiate new linked list LinkedList<Travel> LL = new LinkedList<Travel>(); try { //initiate filereader and bufferedreader objects fr = new FileReader(inFile); br = new BufferedReader(fr); //read 1 line from the file line = br.readLine(); // while line is not null while (line != null) { StringTokenizer tokenizer = new StringTokenizer(line, "|"); index = Integer.parseInt(tokenizer.nextToken()); NRIC = tokenizer.nextToken(); Name = tokenizer.nextToken(); srcCountry = tokenizer.nextToken(); deptDate = tokenizer.nextToken(); deptTime = tokenizer.nextToken(); destCountry = tokenizer.nextToken(); arrDate = tokenizer.nextToken(); arrTime = tokenizer.nextToken(); //create new Travel object Travel travel = new Travel(index, NRIC, Name, srcCountry, deptDate, deptTime, destCountry, arrDate, arrTime); //add this item object to Llist LL.addFirst(travel); //read another line from file line = br.readLine(); } //close buffered reader br.close(); } catch (FileNotFoundException e) { System.out.println("The file" + inFile + "was not found"); } catch (IOException e) { System.out.println("Reading error"); } finally { //close filereader if (fr != null) { try { fr.close(); } catch (IOException e) { System.out.println("error closing file"); } //print out the input prompt } } //create readers to read from user input try { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); //read one line from user line = reader.readLine(); while (!line.equals("0")) { line = reader.readLine(); System.out.println(INPUT_PROMPT1); //read one line from user if (line.equals("1")) { System.out.println(IC_PROMPT); BufferedReader IC = new BufferedReader(new InputStreamReader(System.in)); line = IC.readLine(); for (int n = 0; n < LL.size(); n++) { if (LL.get(n).NRIC.toUpperCase().contains(line.toUpperCase())) { //printout information of the video System.out.println(LL.get(n)); } } } else if (line.equals("2")) { System.out.println(Dept_PROMPT); BufferedReader Dept = new BufferedReader(new InputStreamReader(System.in)); line = Dept.readLine(); for (int n = 0; n < LL.size(); n++) { if (LL.get(n).deptDate.toUpperCase().contains(line.toUpperCase())) { //printout information of the video System.out.println(LL.get(n)); } else { System.out.println("No such record"); } } } else if (line.equals("3")) { for (int n = 0; n < LL.size(); n++) { System.out.println(LL.get(n)); } } else if (line.equals("4")) { System.out.println(Insert_Remove_PROMPT); BufferedReader Insert = new BufferedReader(new InputStreamReader(System.in)); line = Insert.readLine(); if (line.equals("1")) { System.out.println(Delete_Record); } else if (line.equals("2")) { System.out.println(Insert_Record); } else if (line.equals("3")) { System.out.println(""); } else if (line.equals("5")) { System.out.println("Are you sure you want to exit? Y/N"); BufferedReader exit = new BufferedReader(new InputStreamReader(System.in)); line = exit.readLine(); if (line.equalsIgnoreCase("Y")) { System.exit(0); } } } } } catch (IOException e) { System.out.println("error"); } } }
Vaibhav Mittal
Greenhorn
Posts: 23
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Could you describe your problem in a little more detail?
"Life is good"
Abhradeep Banerjee
Ranch Hand
Posts: 71
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
sure at line 118 when i put the INPUT_PROMPT
i get display as blank but if i put INPUT_PROMPT before that while loop i dont get that error im not sure why
Tom Reilly
Rancher
Posts: 618
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I tried compiling your code but failed because the class Travel does not exist.
Vaibhav Mittal
Greenhorn
Posts: 23
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I think you need to put the statement
System.out.println(INPUT_PROMPT1);
before the line
line = reader.readLine();
I think that should work. Just interchange the lines 117 and 118 and check.
"Life is good"
Abhradeep Banerjee
Ranch Hand
Posts: 71
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
alright here's the code for Travel Class do you want me to paste for the Travel text file as well??
i tried interchanging still turns out blank
public class Travel { // declare all var to contain the fields of a record int index; String NRIC; String Name; String srcCountry; String deptDate; String deptTime; String destCountry; String arrDate; String arrTime; //creates constructor to store all the fields into the var public Travel(int index, String NRIC, String Name, String srcCountry, String deptDate, String deptTime, String destCountry, String arrDate, String arrTime) { this.index = index; this.NRIC = NRIC; this.Name = Name; this.srcCountry = srcCountry; this.deptDate = deptDate; this.deptTime = deptTime; this.destCountry = destCountry; this.arrDate = arrDate; this.arrTime = arrTime; // create a toString () method to return sting in the same delimited //format as input record } public String toString(){ return(index+ "|" + NRIC + "|" + Name + "|" + srcCountry + "|" +deptDate + "|" +deptTime + "|" +destCountry + "|" + arrDate + "|" + arrTime ); } }
Tom Reilly
Rancher
Posts: 618
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
do you want me to paste for the Travel text file as well??
Yes please. I can compile now but not run.
Abhradeep Banerjee
Ranch Hand
Posts: 71
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
yes i know that
if i place the input prompt on line 97 it works
Abhradeep Banerjee
Ranch Hand
Posts: 71
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
found the solution i just put the input prompt at the beginning before readline and at the end of the while loop
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
insertion and deletion of record from a text file
unable to exit program..
travel agent - outofmemory heap error
Numberformat exception
travel agent - java writing to file via user input
More...