0
當我編譯我的bankSim類時,出現錯誤:非靜態方法setWhichQ(int)不能從靜態上下文中引用。我能做些什麼來引用bankSim類中的Event類方法?就在這之下是processArrival,它是發生錯誤的地方。之後是我的整個活動課。如何在bankSim類中使用我的Event類方法?
public void processArrival(Arrival arrEvent, Arrival[] inputData, int inputDataIndex,
SortedList<Event> eventList, QueueDSVector<Arrival> teller1, QueueDSVector<Arrival> teller2) {
boolean atFront1 = teller1.isEmpty(); // am I the only one here?
boolean atFront2 = teller2.isEmpty();
if (atFront1) { // if no other customers, then immediately get served
Departure newDep = new Departure(arrEvent.getArrTime(), arrEvent);
// because this customer's next Event will be a departure
eventList.insert(newDep); // put the departure into eventList
} // end if
else if (atFront2) { // if no other customers, then immediately get served
Departure newDep = new Departure(arrEvent.getArrTime(), arrEvent);
// because this customer's next Event will be a departure
eventList.insert(newDep); // put the departure into eventList
} // end if
else if (teller1.size()< teller2.size()) { //queue of teller 1 is less than teller 2
teller1.enqueue(arrEvent); // put new customer into bank line to wait
Event.setWhichQ(1);
}
else if (teller2.size() < teller1.size()) {
teller2.enqueue(arrEvent);
Event.setWhichQ(2);
}
public abstract class Event implements Comparable<Event> {
protected int whichQ;
public Event() {
whichQ = 0;
}
public int compareTo (Event other) {
int thisTime = this.getTime();
int otherTime = other.getTime();
return (thisTime - otherTime);
}
public int getWhichQ() {
return whichQ;
}
//
public void setWhichQ(int q) {
if (q >= 2)
whichQ = 2;
else if (q<=1) // < 0 = 0
whichQ = 1;
else
whichQ = q;
}
public abstract int getTime();
public abstract String toString();
} // end Event class
這是什麼編程語言?你所包含的唯一標籤是靜態方法。 – furkle 2014-10-29 20:26:29
@furkle爪哇,對不起剛剛添加它的回合 – 2014-10-29 20:46:40
添加了下面的解釋。 – furkle 2014-10-29 20:50:34