jeudi 18 février 2016

I'm trying to iterate through an array list, find the first item in the array in which the boolean is false, set it to true and return it

this is my method to add a taxi driver

public class TaxiController {

ArrayList TaxiList = new ArrayList();

public void addTaxi(String cabNumber, String driver, boolean booked){
    //add a taxi to the taxi list
    Taxi deltaTaxis = new Taxi(cabNumber, driver, booked);
    TaxiList.add(deltaTaxis);

}

this is my for loop, attempting to iterate through the array list, find the first false boolean and set it to true

public void bookTaxi(){
    //book a taxi
    for (int i = 0; i < TaxiList.size(); i++){
        if (i == false) {
            (i == true);
        }
        return (i);
    }

}


public class KwikTaxi {
    //name taxi company
    TaxiController delta;

    public KwikTaxi(){
    //add taxis to the taxi queue, set booked to false as default
    addTaxis();

}

here i've added a few items into the array and set them to false by default

public void addTaxis(){
    delta = new TaxiController();

    delta.addTaxi("001", "John", false);
    delta.addTaxi("002", "Pete", false);
    delta.addTaxi("003", "Chris", false);
    delta.addTaxi("004", "Will", false);
    delta.addTaxi("005", "Emma", false);
    delta.addTaxi("006", "Joe", false);
    delta.addTaxi("007", "Rhys", false);
    delta.addTaxi("008", "Colm", false);
    delta.addTaxi("009", "Steve", false);
    delta.addTaxi("010", "Matthew", false);

}
}

Aucun commentaire:

Enregistrer un commentaire