• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

criteriaFind complexity?

 
Matt Bucknam
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on my criteriaFind method and feel like I am getting bogged down with a very deeply nested looping structure.
Please tell me if I am on the wrong track or not:
Start the method by tokenizing the criteria into a 2-dimensional array of name-value pairs.
Then for each database record:
check for each token, first, does the name match a column.
If it does, does the value match the value of that
column.
If it does add the record to the datainfo array for
return.
It seems the only way to successfully implement this method requires at least 3 nested for loops with evaluations in each.
Just want to make sure that I am not missing some obvious and simple solution.
 
Paul Smiley
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have the right idea, but I want to point out a few things:
1) you are only querying against ORIG and DEST airports. - there is no need to go through the entire record
while more records{
if orig matches record[1]{
if dest matches record[2]{found = true;}
}
}
2) it will be easier to use a vector than an array since you don't know how many records match. then do an arrayCopy to populate your array.
let me know what you think
 
Matt Bucknam
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good to know I am at least not off in left field. The instructions indicate that the method has to accept a comma-separated list of name-value pairs but does not specifically say which pairs.
It so happens that origin and destination are the only two we are sending in this assignment but don't you think the grader is going to want a generic criteriaFind which is independent of database schema and can accept/handle any of the columns defined for that particular database?
I don't want to go any further than the requirements for the assignment for sure, but I don't want to come up short either. What do you think?
 
Paul Smiley
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're right, of course, about the future enhancements. I coded mine with that in mind. I personally used an inner while loop (intstead of the nested if's)with the breaking condition the number of criterion being passed. Inside the while loop, you break if you get even one false; if it maxes out without a false, then that is a match and you add it to your collection. That way you can have any number of criterion and it will work. Or you could enumerate across the record indices in a while loop....
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul:
Are you sure we only need to search the Dest and Orig? Because I thought the user can serach for anything.
 
Paul Smiley
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my instructions under 'user interface' it says:
The user should be able to select the origin and destination of flights, and the display should update to show only flights that satisfy those criteria. The user must be able to describe "any" for the origin, destination, or both, so as to implement a wildcard-like feature.
Doesn't say anything else about other fields...
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul: it says "user interface", that's why my interface has two fields. But it doesn't say anything about the search on the data class.
Can anyone help us out here?
 
Paul Smiley
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I'd like to hear from those who passed the exam what they did...
But if you write your criteriaFind properly, you wouldn't have to modify it to allow future enhancements. Depending on how many name value pairs you pass, it should be able to check the db against that.
I guess that's a judgement we have to make - adding additional functionality verses allowing it to be modifiable for future use.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic