Note that there are some explanatory texts on larger screens.

plurals
  1. POSearching object arraylist confusion
    text
    copied!<p>I wrote a method for searching an object in my arralist, however I need this search to take two parameters and compare them to the description of the object. What it is confusing me is that I do not know how to make my method take two parameter and those two parameters compare to one single description. e.g Description of object: Blue Mustang</p> <p>Now the search method has to take two parameters in this case one String "Blue" and one String "Mustang" and I do not have a clue how to do it. I found a way to just write the complete description as one parameter and works perfectly. I am leaving the method that I tried to change to look for two parameters and as well the method that takes one parameter and works fine. It is important to mention that the method also needs to look for cars that are not on loan so thats why there is also a comparison to the hire date since if the car is on loan will have one and if not it wouldn't.</p> <p>Trying to change it to look for two parameters:</p> <pre><code>public Car searchCar(String description, String description2) { for (Car car : cars) { if (car.getDescription().equals(description) &amp;&amp; car.getDescription().equals(description2) &amp;&amp; car.getHireDate().equals("")) { System.out.println( ": " + car.getDescription() + " rate: £" + car.getDailyRate() + " Down payment: £"+ car.getDownPayment()); return car; } else if (car.getHireDate() != ("")) { System.out.println("This car is rented!!"); } else { } } return null; } </code></pre> <p>This is the one that takes one parameter and works fine:</p> <pre><code>public Car searchCar(String description) { for (Car car : cars) { if (car.getDescription().equals(description) &amp;&amp; car.getHireDate().equals("")) { System.out.println( ": " + car.getDescription() + " rate: £" + car.getDailyRate() + " Down payment: £"+ car.getDownPayment()); return car; } else if (car.getHireDate() != ("")) { System.out.println("This car is rented!!"); } else { } } return null; } </code></pre>
 

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