This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Search Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Search" Watch "Search" New topic
Author

Search

Rahim Nathwani
Greenhorn

Joined: Sep 19, 2005
Posts: 19
For the requirment:
It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user.

My interpretation for the method find(String[] criteria):
1. criteria{null,null,null,null......} - Display all records
2. criteria{"Fr",null,null,null......} - Display all records that name starts with "Fr"
3. criteria{null,"Ed",null,null......} - Display all records that location starts with "Ed"
4. criteria{"Fred","Ed",null,null......} - Display all records that name starts with "Fr" AND location starts with "Ed"

I'm not sure if point number 4 is correct - Anyone have thought about this requirement?

Thanks
Rahim Nathwani
Greenhorn

Joined: Sep 19, 2005
Posts: 19
Sorry number 4 has a typo:

4. criteria{"Fr","Ed",null,null......} - Display all records that name starts with "Fr" AND location starts with "Ed"

thanks
Tim Anlauf
Greenhorn

Joined: Oct 11, 2006
Posts: 22
Yes, that's excactly the way I have implemented it.
Rahim Nathwani
Greenhorn

Joined: Sep 19, 2005
Posts: 19
I just realized something in my assignment

The instructions.html states:
It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user.

The DB intergace states:
// Returns an array of record numbers that match the specified
// criteria. Field n in the database file is described by
// criteria[n]. A null value in criteria[n] matches any field
// value. A non-null value in criteria[n] matches any field
// value that begins with criteria[n]. (For example, "Fred"
// matches "Fred" or "Freddy".)


public int[] find(String[] criteria) {
return null;
}

Which search do I do? Match exactly or "Fred" results in a return of "Freddy"?
Jeremy Botha
Ranch Hand

Joined: Feb 16, 2005
Posts: 125
Hi, Rahim.

I followed the contract specified in the DBMain interface, and matched anything which started with the specified search term.

There are a number of WTF's in the documentation. I assume you're working on B&S?

Jeremy


McFinnigan? Never heard of him. Nobody here but us chickens...<br /> <br />SCJP for Java 1.4<br />SCJD for Java 5.0
Marcelo Ortega
Ranch Hand

Joined: May 31, 2005
Posts: 519

When i first read the instruction on this point i interpreted it as having a button where the user can click on "Search All" which will show all fields, and two JTextFields, one for name and another for location (with a "Search" button), where the user can specify the name and/or location criteria. After reading a couple of threads i noticed that i had interpreted the instructions incorrectly, and that i should allow the user to be able to specify a value for any of the database fields. Is this correct? My instructions state the same as the first post:
It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user


If i am right, this would be quit ugly for the GUI. Any thoughts?

Regards.
[ October 31, 2006: Message edited by: Marcelo Ortega ]

SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD, SCEA/OCMJEA

Live life to an interface, not an implementation!
Rahim Nathwani
Greenhorn

Joined: Sep 19, 2005
Posts: 19
Hi jeremy,

You got it with the WTF --- Too many

I'm working on UrlyBird - Room rental. I have decided exactly what you did as far as the search. I am searching anything which started with the specified search term. So if the search is "Fr" --> returns "French", "Fred" ---> NOT "fred" ie. Case sensitive

Marcelo,

I have understood the search as you have. I don't think that we need a search on every column. Love for someone who has passed the certification doing it this way to conform.
Marcelo Ortega
Ranch Hand

Joined: May 31, 2005
Posts: 519

Hi Rahim,
If this is so, then the findByCriteria(String[] criteria) method is quit stupid, because it says that field n matches criteria[n], and if we are only providing values for the name and location, what happens to the rest of the positions in the array?? I think explicitly setting them to null is pretty dum, don't you think?

Anyone got a different view on this?

Regards.
Mark Smyth
Ranch Hand

Joined: Feb 04, 2004
Posts: 288
Originally posted by Marcelo Ortega:
Hi Rahim,
If this is so, then the findByCriteria(String[] criteria) method is quit stupid, because it says that field n matches criteria[n], and if we are only providing values for the name and location, what happens to the rest of the positions in the array?? I think explicitly setting them to null is pretty dum, don't you think?

Anyone got a different view on this?

Regards.



Yes but creating a String array will auutomatically set all the values to null, so you need only set the criteria fields you are interested in.


while the search method as called by the GUI only requires the name and location fields to be searchable, it seems natural that it should be implemented in a way that would make it easy to add new fields to search on if a future search enhancement is required (I think the GUI requirement hint at this point too, ie establishing a framework ...).

My criteria method is a case insensitive startWith comparison of each field. I think that a case sensitive approach is not very user friendly at all and that a case insensitive search is very justifiable on these grounds.


SCJP<br />SCJD
 
Consider Paul's rocket mass heater.
 
subject: Search