Introducing Polymorphism: Replacing two array-lists with a single array-list (Java)
<p>For an assignment I'm working on introducing polymorphism and inheritance to an existing program. </p>

<p>The issue I'm currently having is replacing two separate lists with a single list. I'm pretty new to Java programming (read: not that good at it) so I apologize if this is in anyway unclear.</p>

<pre><code>public class TaxiCo
{
    // The name of this company.
    private String companyName;
    // The name of the company's base.
    private final String base;    
    // The fleet of taxis.
    private ArrayList&lt;Taxi&gt; taxiFleet;
    // The fleet of shuttles.
    private ArrayList&lt;Shuttle&gt; shuttleFleet;
    // The fleet of vehicles.
    private int nextID;
    // A list of available destinations for shuttles.
    private ArrayList&lt;String&gt; destinations;
</code></pre>

<p>I need to replace <code>ArrayList&lt;Shuttle&gt; shuttleFleet</code> and <code>ArrayList&lt;Taxi&gt; taxiFleet</code> with <code>ArrayList&lt;Vehicle&gt;</code>.</p>

<p>When I originally added <code>ArrayList&lt;Vehicle&gt; vehicleFleet</code> I thought I needed to make a new method called <code>addVehicle</code> but decided against it for the time being (I'll include the code for that method incase someone thinks I was headed down the right path).</p>

<p>So I simply added the following:</p>

<p>field:</p>

<p><code>private ArrayList&lt;Vehicle&gt; vehicleFleet;</code></p>

<p>constructor: </p>

<p><code>vehicleFleet = new ArrayList&lt;Vehicle&gt;();</code></p>

<p>made the changes to the following methods: </p>

<pre><code>public void addTaxi(Vehicle vehicle)
{
   Vehicle taxi = new Taxi(base, "Car #" + nextID);
   vehicleFleet.add(taxi);
   // Increment the ID for the next one.
   nextID++;
}
</code></pre>

<p>...and something similar for <code>addShuttle</code>.</p>

<p>EDIT: 
But when I attempted to compile, this code is highlighted: <code>new Taxi(base, "Car #" + nextID);</code> <a href="https://i.stack.imgur.com/IMOJ4.png" rel="nofollow noreferrer">and I get this error message.</a></p>

<p>Thoughts on how to fix this? I'm also open to any and all criticism if you think it'll help me code better or gain a better understanding of the java language. Thanks!</p>

<p>Here's the rest of the code for the TaxiCo class if it helps.</p>

<pre><code>public TaxiCo(String name, String base)
{
    companyName = name;
    base = "base";
    taxiFleet = new ArrayList&lt;Taxi&gt;();
    shuttleFleet = new ArrayList&lt;Shuttle&gt;();
    nextID = 1;
    destinations = new ArrayList&lt;String&gt;();
    fillDestinations();
}

public void addTaxi(Vehicle vehicle)
{
    Taxi taxi = new Taxi(base, "Car #" + nextID);
    taxiFleet.add(taxi);
    // Increment the ID for the next one.
    nextID++;
}     

public void addShuttle()
{
    // Sanity warning:
    // The following is a thoroughly contrived way to create a route!

    // Create a random list of destinations for its route.
    Collections.shuffle(destinations);
    ArrayList&lt;String&gt; route = new ArrayList&lt;String&gt;();
    // The starting point is always the base.
    route.add(base);
    // Decide on an (arbitrary) length for all routes.
    final int ROUTE_LENGTH = 3;
    for(int i = 0; i &lt; ROUTE_LENGTH; i++) {
        route.add(destinations.get(i));
    }

    Shuttle shuttle = new Shuttle("Shuttle #" + nextID, route);
    shuttleFleet.add(shuttle);
    // Increment the ID for the next one.
    nextID++;
}


public Vehicle lookup(String id)
 {
    boolean found = false;
    Vehicle vehicle = null;
    Iterator&lt;vehicle&gt; it = vehicleFleet.iterator();
    while(!found &amp;&amp; it.hasNext()) {
        vehicle = it.next();
        if(id.equals(vehicle.getID())) {
            found = true;
         }
        else{
            return null;
        }
    }
}

    public void showStatus()
{
    System.out.println("Current status of the " + companyName + " fleet");
    for(Taxi taxi : taxiFleet) {
        System.out.println(taxi.getStatus());
    }
    for(Shuttle shuttle : shuttleFleet) {
        System.out.println(shuttle.getStatus());
    }
}


private void fillDestinations()
{
    destinations.add("Canterbury West");
    destinations.add("Canterbury East");
    destinations.add("The University");
    destinations.add("Whitstable");
    destinations.add("Herne Bay");
    destinations.add("Sainsbury's");
    destinations.add("Darwin");
}
</code></pre>

<p>...And that <code>addVehicle</code> method I was talking about earlier.</p>

<pre><code>public void addVehicle(Vehicle vehicle)
{
    Vehicle taxi = new Taxi(base, "Car #" + nextID);
    //taxiFleet.add(taxi);
    fleet.addVehicle(taxi);
    //Increment the ID for the next one. but do we need two...
    nextID++;

    //Create a random list of destinations for its route.
    Collections.shuffle(destinations);
    ArrayList&lt;String&gt; route = new ArrayList&lt;String&gt;();
    //The starting point is always the base.
    route.add(base);
    //Decide on an arbitrary length for all routes.
    final int ROUTE_LENGTH = 3;
    for(int i = 0; i &lt; ROUTE_LENGTH; i++) {
        route.add(destinations.get(i));
    }

    Vehicle shuttle = new Shuttle("Shuttle #" + nextID, route);
    //shuttleFeet.add(shuttle);
    fleet.addVehicle(shuttle);
    nextID++;
}
</code></pre>

<p>EDIT: Here are the other three classes mentioned:</p>

<p>Vehicle class:</p>

<pre><code>public class Vehicle
{
// A unique ID for taxi/shuttle.
protected String id;
//private String id;
// The next destination of this taxi/shuttle.
//private String destination;
protected String destination;
// The location of this taxi/shuttle.
//private String location;
protected String location;
//The fleet of taxis and shuttles.
//protected ArrayList&lt;Vehicles&gt; vehicles;

/**
 * Constructor for objects of class Vehicle
 */
public Vehicle(String destination, String base, String id)
{
    // initialise instance variables.
    //this();
    this.id = id;
    //this.destination = destination;
    location = base;
    destination = null;
}

 /**
 * Return the ID of the taxi/shuttle.
 * @return The ID of the taxi/shuttle.
 */
public String getID()
{
    //return this.id;
    return id;
}

/**
 * Accessor method for the taxi/shuttle ID.
 */
protected void setID(String id) 
{
    this.id = id;
    //return id;
}

/**
 * Return the destination of the taxi/shuttle.
 * @return The destination of the taxi/shuttle.
 */
public String getDestination()
{
    return destination;
}

/**
 * Set the intended destination of the taxi/shuttle.
 * @param destination The intended destination.
 */
public void setDestination(String destination)
{
    this.destination = destination;
}

/**
 * Return the location of the taxi/shuttle.
 * @return The location of the taxi/shuttle.
 */
public String getLocation()
{
    return location;
}

/**
 * Set the intended location of the taxi/shuttle.
 * @parm location The intended location.
 */
public void setLocation(String location)
{
    this.location = location;
}

/**
 * Return the status of this taxi/shuttle.
 * @return The status.

public String getStatus()
{
    return id + " at " + location + " headed for " +
           destination;
}
*/
</code></pre>

<p>Taxi class:</p>

<pre><code>public class Taxi extends Vehicle
{
//Moved to the Vehicle SuperClass.
//private String id;
// The destination of this taxi.
//private String destination;
// The location of this taxi.
//private String location;
// Whether it is free or not.
private boolean free;

/**
 * Constructor for objects of class Taxi.
 * @param base The name of the company's base.
 * @param id This taxi's unique id.
 */
public Taxi(String destination, String id, String base)
{
    //this.id = id;
    //super();
    super(destination, id, base);
    //location = base;
    //super(location);
    //destination = null;
    free = true;
}

/**
 * Book this taxi to the given destination.
 * The status of the taxi will no longer be free.
 * @param destination The taxi's destination.
 */
public void book(String destination)
{
    setDestination(destination);
    free = false;
}

/**
 * Return the status of this taxi.
 * @return The status.
*/
public String getStatus()
{
    return id + " at " + location + " headed for " +
           destination;
}


/**
 * Return the ID of the taxi.
 * @return The ID of the taxi.

public String getID()
{
    //return id;
}
*/

/**
 * Accessor method for the taxi/shuttle ID.
 */
public void setID(String id)
{
    super.setID(id);
    //return id;
}

/**
 * Return the location of the taxi.
 * @return The location of the taxi.

public String getLocation()
{
    return location;
}
*/

/**
 * Return the destination of the taxi.
 * @return The destination of the taxi.

public String getDestination()
{
    return destination;
}
*/

/**
 * Set the intented destination of the taxi.
 * @param destination The intended destination.
 */
public void setDestination(String destination)
{
    super.setDestination(destination);
    //return destination;
}

/**
 * Set the intented destination of the taxi.
 * @param destination The intended destination.
 */
public void setLocation(String location)
{
    super.setLocation(location);
    //return location;
}

/**
 * Indicate that this taxi has arrived at its destination.
 * As a result, it will be free.
 */
public void arrived()
{
    location = destination;
    destination = null;
    free = true;
}
}
</code></pre>

<p>Shuttle class: </p>

<pre><code>public class Shuttle extends Vehicle
{
//Moved to the Vehicle SuperClass.
//private String id;
// The next destination of this shuttle on its
// circular route.
//private String destination;
// The location of this shuttle.
//private String location;
// The circular route of this shuttle.
private ArrayList&lt;String&gt; route;
// The destination number in route that the shuttle is
// currently headed for.
private int destinationNumber;

/**
 * Constructor for objects of class Shuttle
 * @param id This shuttle's unique id.
 * @param route The route taken by this shuttle.
 *              The first entry is the starting location.
 */
public Shuttle(String destination, String id, String base, ArrayList&lt;String&gt; route)
{
    //this.id = id;
    super(id, destination, base);
    setRoute(route);
}

/**
 * Return the status of this shuttle.
 * @return The status.
 */ 
public String getStatus()
{
    return id + " at " + location + " headed for " +
           destination;
}


/**
 * Return the ID of the shuttle.
 * @return The ID of the shuttle.

public String getID()
{
    return id;
}
*/

/**
 * Accessor method for the taxi/shuttle ID.
 */
public void setID(String id)
{
    super.setID(id);
    //return id;
}

/**
 * Return the location of the shuttle.
 * @return The location of the shuttle.

public String getLocation()
{
    return location;
}
*/

/**
 * Return the destination of the shuttle.
 * @return The destination of the shuttle.

public String getDestination()
{
    return destination;
}
*/

/**
 * Indicate that this shuttle has arrived at its next destination.
 */
public void arrived()
{
    location = destination;
    setNextDestination();
}

/**
 * Set the next destination of the shuttle.
 */
private void setNextDestination()
{
    destinationNumber++;
    if(destinationNumber &gt;= route.size()) {
        // End of the circular route.
        // Start from the beginning again.
        destinationNumber = 0;
    }
    setDestination(route.get(destinationNumber));
}

/**
 * Set the intented destination of the suttle.
 * @param destination The intended destination.
 */
public void setDestination(String destination)
{
    //this.destination = destination;
    super.setDestination(destination);
    //return destination;
}

 /**
 * Set the intended location of the taxi/shuttle.
 * @parm location The intended location.
 */
public void setLocation(String location)
{
    this.location = location;
}

/**
 * Set the route for this shuttle.
 * @param route The circular list of destinations.
 */
private void setRoute(ArrayList&lt;String&gt; route)
{
    // Make a copy of the list parameter.
    this.route = new ArrayList&lt;String&gt;();
    this.route.addAll(route);
    destinationNumber = 0;
    location = route.get(destinationNumber);
    setNextDestination();
}
</code></pre>

<p>}</p>