Note that there are some explanatory texts on larger screens.

plurals
  1. POrenting, showing and returning a car arraylist not working properly
    text
    copied!<p>Well basically I have an assignment that has to be done for January. I have to to create a mock rental service that allow customers to rent cars. I am basing the logic off of an ArrayList, using its methods to manage my car collection.</p> <p>I have some problems with my code, the logic in a lot of my methods is not working correctly. In the code sample I included the <code>showCar</code>, <code>rentTheCar</code> and <code>returnCar</code> methods are not working as they should. The <code>showCar</code> method displays all the cars, although when invoking the method it asks me for the <code>carNumber</code>. The <code>rentThecar</code> and <code>returnCar</code> seem to be renting/returning all cars, instead of just the one I specify.</p> <p>I am showing relevant code from my classes below, if anyone can help me figure out where I might have gone wrong.Please I want to make it clear that i do not want my homework done just some guidance. Thanks.</p> <p>Show car method:</p> <pre><code>public void showCar (int carNumber) { if (cars.size() &lt; 0 ) { System.out.println ("Add cars first!!!"); } else if (carNumber &lt; cars.size()) { System.out.println(cars.get(carNumber)); } else{ System.out.println("Error!! This note cannot be shown, because it does not exist!!"); } } </code></pre> <p>Rent car method:</p> <pre><code>public void rentTheCar (int carNumber, String CustomerName, String hireDate, String returnDate, int daysOfHire) { if (cars.size() &lt; 0) { System.out.println("Empty list!! Add cars first!!"); } else if (carNumber &gt; cars.size()) { System.out.println("This car does not exist!!"); } else { for (Car car : cars) { int index = 0; cars.get (carNumber); car.rentTheCar(CustomerName, hireDate, returnDate, daysOfHire); index ++; } } } </code></pre> <p>Return car method:</p> <pre><code>public void returnCar (int carNumber) { cars.get(carNumber); if (cars.size() &lt; 0) { System.out.println("Error!! It is impossible to return a car from an empty list"); } else if (carNumber &gt; cars.size()) { System.out.println("Error!! Not a valis car!!"); } else { for (Car car : cars) { car.returnTheCar(); System.out.println ("The car has been returned correctly"); } } } </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