• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I/O: searching an address book text file

 
N. Gonzalez
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy all...confused newbie cowpoke here....

I'm stuck on how to proceed with this...any guidance would be appreciated...see my code so far...am I on track?

Thanks in advance!

 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're trying to write the whole program "top-down." This is rarely a good approach, because until you're completely done, you've got nothing. Instead, write it bottom up, iteratively, a little at a time.

1) Write a program which opens a file, reads a line of text, prints it, closes the file. Make sure it works.

2) Write a program which opens a file, reads all the text, prints them, closes the file. Make sure it works.

3) Write a program which takes two Strings as command-line arguments, and prints "OK" if they're equal. Test this too.

4) Write a program which takes one String as a command-line argument, opens a file, reads each line of the file, prints the matching ones. Test.

5) Define a file format for your address book file. Create the file in an editor.

6) Write a program which reads the first and only the first address record from such a file, and prints it out. Test.

7) Now you have examples of all the pieces you need. Write the complete program -- and test it!
 
N. Gonzalez
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you clarify what you mean by:

Define a file format for your address book file. Create the file in an editor.


I thought I was to use the text file as is.
 
N. Gonzalez
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Help...already having difficutly following the advice given...more confused than ever....

What's wrong with my BufferedReader/FileReader statement?

Getting an error about ')' expected ???

 
Kristin Stromberg
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means exactly what it says - you're missing a ")" at the end of
 
N. Gonzalez
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, BIG DUH...how could I not see that?

Thanks.
 
N. Gonzalez
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But I could still use clarification on...


Define a file format for your address book file. Create the file in an editor.


I'm not supposed to access the 'addrbook.txt' file as is?
 
N. Gonzalez
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And I'm also trying to see in which one of these six smaller programs I'll be utilizing String Tokeninizing, which my instructor indicated we should be using to split the data into multiple elements.

Thank you. No for me tonight...
 
N. Gonzalez
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Headed to the bookstore today to look through Java books to help my confusion...

Can anyone recommend any books with lots of code samples on I/O with VERY CLEAR explanations in everyday language (not programmer to programmer) OR any with examples or exercises of this bottom up approach --building little programs at a time to then use the pieces to write the larger program.
 
Kristin Stromberg
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java Tutorial has a section on I/O here.

As far as books are concerned, I highly recommend Head First Java.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by N. Gonzalez:

I'm not supposed to access the 'addrbook.txt' file as is?


I'm sorry, N. (I wish you'd use a proper first name -- it's hard to address a person by their initial.) This is my fault. I didn't read closely enough to realize that the problem statement tells you exactly how to store the data (although, actually, I'm not sure it does -- what if the address contains a comma? I guess you can simply ignore that possibility for now.) Ignore my step 5 -- consider it done.
 
N. Gonzalez
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My name is Nancy. I had to assume that #5 didn't apply.

Actually, because the components of each record are separated by a comma (Last Name, First Name, Address, City, State, Zip, Telephone), that's why I had asked about String Tokenizing. Was unclear on how to go about doing that for each line read and how to refer to only the first token of each line (the last name).

My assignment's due by midnight. I haven't successfully completed all the pieces you suggested, so chances are I won't make my deadline. Hopefully I'll get partial credit for what I do turn in. Bummer...

Thanks for your help.

(By the way, loved the drawing of your daughter on your weblog. I myself am fortunate to have a happy, spirited daughter!)
 
Kristin Stromberg
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nancy - have you looked at the split method (in the String class)? I think this would be easier/more appropriate than StringTokenizer. I don't know what timezone you are in, but chez moi, you still have almost four hours to finish! Good luck!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic