Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your meetsCriteria() method seems a little bit complicated and misses a lot of combination of criteria that are specified or not. Since you have 4 parameters and each parameter can be specified or not, you have 16 (2^4) possible different cases. Obviously, you code doesn't contain that many. The number of possible cases doubles for each field you add to this Restaurant class. You must find a way to avoid this combinatory explosion by making sure that you only need to add one test for each field.</p> <p>Can I suggest you try this way:</p> <pre><code>public class Restaurant { private String _name; private String _address; private String _phoneNum; private Area _area; public boolean meetsCriteria(String name, String area, String phone, String category) { if ( !name.equals("") &amp;&amp; !name.equals(this._name) &amp;&amp; this._name.indexOf(name) &lt; 0){ // name has been specified and does not match return false; } if(!areas.equals("") &amp;&amp; this._aread.getArea().equals(area)){ // area has been specified and does not match return false; } // ... snip ... // do the same kind of thing for phone and category // ... snip ... // At this point, all the criteria that have been specified by the user match, // and all the criteria that haven't been specified have been ignored. return true; } } </code></pre> <p>You can probably do all that in one huge if() statement, but that would probably not be very readable.</p> <p>Or even better, you can extract the matching logic for each of your fields to their own method, like so:</p> <pre><code>public class Restaurant { private String _name; private String _address; private String _phoneNum; private Area _area; public boolean meetsCriteria(String name, String area, String phone, String category) { return matchesName(name) &amp;&amp; matchesArea(area) &amp;&amp; matchedPhone(phone) &amp;&amp; matchesCategory(category); } private boolean matchesName(String name){ return name.equals("") || name.equals(this._name) || this._name.indexOf(name) &gt;= 0; } private boolean matchesArea(String area) { return areas.equals("") || this._aread.getArea().equals(area); } // create the missing methods yourself. } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload