473,545 Members | 2,049 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Java, Searching through array question

3 New Member
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.leng th; 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.leng th; row++)
{
for (col=0; col<matrix[row].length; col++)
outFile.print(m atrix[row] [col].toUpperCase() + System.getPrope rty("line.separ ator"));
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.prin tln("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
5 2514
BigDaddyLH
1,216 Recognized Expert Top Contributor
If you were doing it by hand how would you do it? Now how would you turn that into code?
Mar 11 '08 #2
benyboy
3 New Member
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
sukatoa
539 Contributor
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....(t reat 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
1,216 Recognized Expert Top Contributor
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
benyboy
3 New Member
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

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

Similar topics

73
7914
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities as a standard portable part of the core language, the LISP package, and the java.lang package, respectively. Both have big integers, although only...
133
8456
by: Gaurav | last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250 Any comments? Thanks Gaurav
4
1818
by: Rhino | last post by:
I've been playing with Java UDFs for the last couple of days and I've got some questions about scratchpads. I'm running DB2 LUW V8 (FP8) on WinXP. Somewhere in the manuals, I found some remarks that said I could either manage my scratchpad with the getScratchpad() and setScratchpad() methods *OR* set up my own class variables to keep the...
15
6953
by: Paul Morrison | last post by:
Hi all, I need to come up with some differences between arrays in Java and C, I have searched Google and so far all I have found is the following: Arrays in Java are reference types with automatic allocation of memory. In C, arrays are groups of variables of the same type in adjacent memory. Allocation for dynamic arrays is handled by the...
2
1624
by: Carlos K | last post by:
Hello I'm having some difficulty searching a set of rows in a DataRow collection.. This is my question What would be an efficient way to search any column of an DataRow array Let me try to explain the context of this question, that will help you understand what I'm looking for.. Assume that I have a collection of rows that came out of a...
1
9596
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the...
2
6932
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
0
10720
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not...
0
7468
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7423
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5329
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3443
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
704
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.