-1
public Simulator() 
    {
        /** To do Auto-generated constructor stub4 */
        dirs = new ArrayList<LinkedQueue<Vehicle>>();
        for (int i = 0; i < 8; ++i)
            dirs.add(new LinkedQueue<Vehicle>());
        curTime = 0;
        countVehicles = 0;
        trafficLightsState = 0;
        rnd = new Random();
    }

    /** Add some random vehicles to one of eight available directions and  count        number of vehicles to be added. */
    void addRandomVehicles(int count) 
    {
        for (int i = 0; i < count; ++i) 
        {
            /** do not add if limit is reached */
            if (countVehicles == MAX_NUM)
                return;

            /** choose random direction */
            int wh = rnd.nextInt(8);

            /** create vehicle on this direction */
            Vehicle neww = new Vehicle(countVehicles + 1, curTime, 
                    Vehicle.Street.values()[wh / 4], Vehicle.Directiron.values()[wh / 2]);

            /* add to corresponding queue */
            dirs.get(wh).push(neww);
            countVehicles++;
        }
    }

我收到此错误:

Simulator.java:78: cannot find symbol
symbol  : method add(Vehicle)
location: class java.util.ArrayList<jsjf.LinkedQueue<Vehicle>>
            dirs.add(neww);
                ^
Simulator.java:105: cannot find symbol
symbol  : method pop()
location: class jsjf.LinkedQueue<Vehicle>
                    Vehicle cur = dirs.get(j).pop();
                                             ^
2 errors

有什么想法我在这里想念的吗?

4

1 回答 1

1

您已声明 jsjf.LinkedQueue 的 ArrayList 而不是 Vehicle 的 ArrayList。

于 2013-11-07T01:45:10.493 回答