import java.util.LinkedList; public class Simulation { LinkedList list; State s; double time; double runTime; public Simulation() { list=new LinkedList(); s=new State(); time=0; runTime=1000; list.add(new Event ("Arrival",getNextTime())); list.add(new Event("Stop",runTime)); simulate(); } public int getNextTime(){ return 2; } public void simulate(){ boolean end=false; while(!end){ Event e=(Event)list.remove(); if(e.type=="Arrival") arrival(e); else if(e.type.equals("Departure")) departure(e); else end=true; System.out.println(time+"->"+new State().QL); } } public void arrival(Event e){ if(new State().status==0){ new State().status=1; list.add(new Event("Departure",time+this.getNextTime())); } else new State().QL++; list.add(new Event("Arrival",time+this.getNextTime())); } public void departure(Event e){ if(new State().QL>0){ new State().QL--; new State().status=1; list.add(new Event("Departure",time+this.getNextTime())); } else new State().status=0; } public static void main(String []arg){ new Simulation(); } } class State{ int QL; int status; public State(){ QL=0; status=0; } } class Event{ String type; double time; public Event(String ty, double t){ type=ty; time=t; } }