Iteratorinterfaces. One convention in Java is that a collection class acts as its own iterator, meaning that
ArrayList(for instance) implements both interfaces. Let's do the same thing to
Fleetto implement each interface. For
Iterable, we need to implement a single method called
iteratorthat returns an
<E>is something called a generic, which you will learn about later. For now, replace the
Carand define your
iteratormethod as returning an
Iterator. This method should set a counter representing the ``current'' index into the array of
Cars to 0 (resetting the iterator) and return
Iterator, we must implement two methods (the third is optional):
hasNext, which simply indicates if there are any other elements; and
next, which actually gets the next element (
E; don't worry that you have never seen a type called
E, instead give this method a return type of
Car) by returning the element in the array of
Carsat the index indicated by the counter (see bottom of previous paragraph) and incrementing this index.
Fleetclass so that it implements the two interfaces by adding
E, replace it with
Car. Generics are a useful and interesting topic, but beyond the scope of this assignment.
for (Car car : fleet)structure to sequentially print the descriptions of each
Car. This should be an option from the main menu (e.g.: "Enter 'PRINT' to print the fleet"). Use helper methods if/when appropriate.
Submit as per the syllabus.