Пример #1
0
 /** Takes all the information from car and places car in appropriate queue */
 public void pickQueue(Vehicle car) {
   if (car.isTurning()) {
     if (car.getDirection() == Direction.E) {
       EMainTurn.enqueue(car);
     }
     if (car.getDirection() == Direction.W) {
       WMainTurn.enqueue(car);
     }
     if (car.getDirection() == Direction.N) {
       NChurchTurn.enqueue(car);
     }
     if (car.getDirection() == Direction.S) {
       SChurchTurn.enqueue(car);
     }
   } else {
     if (car.getDirection() == Direction.E) {
       EMain.enqueue(car);
     }
     if (car.getDirection() == Direction.W) {
       WMain.enqueue(car);
     }
     if (car.getDirection() == Direction.N) {
       NChurch.enqueue(car);
     }
     if (car.getDirection() == Direction.S) {
       SChurch.enqueue(car);
     }
   }
 }
Пример #2
0
  /** Creates number of vehicles based on reference integer */
  public void populate(int i) {

    Vehicle car = new Vehicle();
    int localcount = 0;
    while (localcount < i) {
      if (counter < 120) {
        car = new Vehicle();
        car.setNumber(counter);
        car.setArrivalTime(time);
        pickQueue(car);
        counter++;
      }

      localcount++;
    }
  }
Пример #3
0
  /**
   * time is advanced here checks which light is on moves as many times as specified by "i" every
   * movement moves time forward 3 also catches emptycollectionexceptions
   */
  public void move(int i) {

    Vehicle car = new Vehicle();
    int localcount = 0;
    while (localcount < i) {
      time += 3;
      if (movingChurch) {
        try {
          car = NChurch.dequeue();
          car.setDepartureTime(time);
          write(car.toString());
          write("\n");
        } catch (EmptyCollectionException e) {
        }

        try {
          car = NChurchTurn.dequeue();
          car.setDepartureTime(time);
          write(car.toString());
          write("\n");
        } catch (EmptyCollectionException e) {
        }

        try {
          car = SChurch.dequeue();
          car.setDepartureTime(time);
          write(car.toString());
          write("\n");
        } catch (EmptyCollectionException e) {
        }

        try {
          car = SChurchTurn.dequeue();
          car.setDepartureTime(time);
          write(car.toString());
          write("\n");
        } catch (EmptyCollectionException e) {
        }

      } else {
        try {
          car = EMain.dequeue();
          car.setDepartureTime(time);
          write(car.toString());
          write("\n");
        } catch (EmptyCollectionException e) {
        }

        try {
          car = EMainTurn.dequeue();
          car.setDepartureTime(time);
          write(car.toString());
          write("\n");
        } catch (EmptyCollectionException e) {
        }

        try {
          car = WMain.dequeue();
          car.setDepartureTime(time);
          write(car.toString());
          write("\n");
        } catch (EmptyCollectionException e) {
        }
        try {
          car = WMainTurn.dequeue();
          car.setDepartureTime(time);
          write(car.toString());
          write("\n");
        } catch (EmptyCollectionException e) {
        }
      }

      localcount++;
    }
  }