By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,865 Members | 1,717 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,865 IT Pros & Developers. It's quick & easy.

Java, Searching through array question

P: 3
hi, after hours of staring at my computer screen, and browsing through various internet forums i am totally stuck!

I have created the following array which reads from an input file the following list of book titles followed by author then book title author etc



Concurrent programming ---- book title
C. R. Snow ---- author
Pascal Precisely ----book title
Judy Bishop ---- author etc
THINKING RECURSIVELY WITH JAVA
ERIC ROBERTS
Concurrent Programming
Stephen J. Hartley
Java Gently
Judith Bishop
Petri Nets
Wolfgang Reisig
Finite Transition Systems
Andre Arnold
Data Structures and Problem Solving Using Java
mark allen weiss



this is the array i have created which reads from the input file



int row, col;
String [] [] matrix = new String [numberOfBooks] [2]
for (row=0; row<matrix.length; row++)
{
for (col=0; col<matrix[row].length; col++)
matrix[row] [col] = inFile.nextLine();
}


when using the following piece of code i am able to print the array

for (row=0; row<matrix.length; row++)
{
for (col=0; col<matrix[row].length; col++)
outFile.print(matrix[row] [col].toUpperCase() + System.getProperty("line.separator"));
outFile.println();
}

when using this code the array is printed as follows which is book title followed by author


CONCURRENT PROGRAMMING
C. R. SNOW

PASCAL PRECISELY
JUDY BISHOP

THINKING RECURSIVELY WITH JAVA
ERIC ROBERTS

CONCURRENT PROGRAMMING
STEPHEN J. HARTLEY

JAVA GENTLY
JUDITH BISHOP

PETRI NETS
WOLFGANG REISIG

FINITE TRANSITION SYSTEMS
ANDRE ARNOLD

DATA STRUCTURES AND PROBLEM SOLVING USING JAVA
MARK ALLEN WEISS



i am now very stuck i need to be able to allow the user to enter the authors surname and then the program will display all books by this author to the outfile (there may be more than one book by the author)

i have started with the following



String AuthorSurname;
System.out.println("please enter an author's surname to view available books"); AuthorSurname = Keyboard.next();

i now need some sort of code which will allow me to display all the books by a particular author.

i very much appreciate any help,
thanks
Mar 11 '08 #1
Share this Question
Share on Google+
5 Replies


BigDaddyLH
Expert 100+
P: 1,216
If you were doing it by hand how would you do it? Now how would you turn that into code?
Mar 11 '08 #2

P: 3
ahh im not sure i seem to be dreaming about code ive seen that much of it.

I Just want the program to output to file all the book titles by the authors with a given surname.
Mar 12 '08 #3

100+
P: 539
If you are trying to search for the books with respect to it's author....

It is better to have a file that was named by that author...

And that file should have the contents ( books ) made by that author....

If the user likes to choose JUDITH BISHOP, just copy the name from the inputfile, and try to search that name in the directory....(treat it as a name of a file )

If successful, then retrieve what that file has....

for example, you have

SNOW
BISHOP
ROBERTS

and i have also files named

SNOW.txt
all books that was made by snow
This..........................................

BISHOP.txt
all books that was made by Bishop
This..........................................

ROBERTS.txt
all books that was made by Roberts
This..........................................


If the user were to choose ROBERTS, you would simply seek the file (ROBERTS.txt) if exists.. Then retrieve that file and show its content...

You must set those files, name it in author, add contents to it, and save....
That is you reference for browsing the books of the author...

Sukatoa...
Mar 12 '08 #4

BigDaddyLH
Expert 100+
P: 1,216
ahh im not sure i seem to be dreaming about code ive seen that much of it.

I Just want the program to output to file all the book titles by the authors with a given surname.
Get a night's sleep then try again. How would you do it by hand?
Mar 12 '08 #5

P: 3
Get a night's sleep then try again. How would you do it by hand?
i did it !!!!!

hard work pays off after all !!
Mar 12 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.