示例#1
0
    /*
     *	Add to the bench with the least amount of people on it
     *
     *	If nothing available return null
     */
    public Bench AddToBench(Passenger passenger)
    {
        // find the bench with the lostwest number of passengers on it
        Bench mostAvailableBench = null;

        foreach (Bench bench in benches)
        {
            if (mostAvailableBench == null)
            {
                mostAvailableBench = bench;
            }
            else if (bench.GetBenchSpaces() > mostAvailableBench.GetBenchSpaces())
            {
                mostAvailableBench = bench;
            }
        }

        // make sure there is a bench available
        if (mostAvailableBench != null)
        {
            mostAvailableBench.AddPassenger(passenger);
            return(mostAvailableBench);
        }

        return(null);
    }