Thank you. There still seems to be a problem with the test. Much of the output of these things is inscrutable to me (and to many of the other students in the class) so I am not always sure what it is supposed to print out. I set it up in the typical fashion, creating a notebook object and storing notes, say 1-5.
Then I list them to see if they list properly, and move on to a search string. I search for, say a two ("2") and it comes up with 2, but then the "Search term not found prints twice, which I don't think it is supposed to.
Do you know what else is missing?
John Simonds
Systems Technologist
simonj2 at sage.edu
(518)244-3111
(518)292-1734
---------------------------------------
Original E-mail
From: Yves Hamel
Sent: 10/02/2006 08:47 AM
To: bluej-discuss at bluej.org, simonj2 at sage.edu
Subject: Re: [Bluej-discuss] ex 4.19
I guess that "Search term not found." should be printed after you'd have searched through all the collection of notes, so you should place it after the while like this :
while(index < notes.size() && !found) {
String note = notes.get(index);
if(note.contains(searchString)) {
found = true;
System.out.println(note);
}
else {
index++;
}
}
if (!found) {
System.out.println("Search term not found.");
}
>>> John Simonds 2006/10/01 12:57 PM >>>
I have a problem printing the search term not found. I originally placed it just before the index ++ but that did not get the desired result.
Here is the code I have written..
_/**
* Search method
*/
public void search(String searchString)
{
int index = 0;
boolean found = false;
while(index < notes.size() && !found) {
String note = notes.get(index);
if(note.contains(searchString)) {
found = true;
System.out.println(note);
}
else {
index++;
}
System.out.println("Search term not found.");
}
}
John Simonds
Systems Technologist
simonj2 at sage.edu
(518)244-3111
(518)292-1734
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.bluej.org/pipermail/bluej-discuss/attachments/20061002/873a93ab/attachment.html