Пример #1
0
  public static void main(String args[]) throws Exception {
    LinkedList<Dog> dogs = new LinkedList<Dog>();
    Dog a1 = new Solution06().new Dog("a1");
    Dog b1 = new Solution06().new Dog("b1");
    Dog c1 = new Solution06().new Dog("c1");
    a1.setOrder(1);
    b1.setOrder(3);
    c1.setOrder(5);
    dogs.add(a1);
    dogs.add(b1);
    dogs.add(c1);

    LinkedList<Cat> cats = new LinkedList<Cat>();
    Cat a2 = new Solution06().new Cat("a2");
    Cat b2 = new Solution06().new Cat("b2");
    Cat c2 = new Solution06().new Cat("c2");
    a2.setOrder(2);
    b2.setOrder(4);
    c2.setOrder(6);
    cats.add(a2);
    cats.add(b2);
    cats.add(c2);

    AnimalQueue zoo = new AnimalQueue();
    zoo.enqueue(a1);
    zoo.enqueue(a2);
    zoo.enqueue(b1);
    zoo.enqueue(b2);
    zoo.enqueue(c1);
    zoo.enqueue(c2);
    System.out.println(zoo.dequeueAny().name);
    System.out.println(zoo.dequeueCats().name);
    System.out.println(zoo.dequeueDogs().name);
  }
Пример #2
0
  public static void main(String args[]) {

    System.out.println("AnimalShelter Sample");

    AnimalQueue a = new AnimalQueue();
    a.enqueue(new Dog("Anthar"));
    a.enqueue(new Dog("Cobo"));
    a.enqueue(new Dog("Simon"));
    a.enqueue(new Cat("Cochino"));

    Animal an = (Animal) a.dequeueAny();

    System.out.println(an.name);
    an = (Animal) a.dequeueCat();
    System.out.println(an.name);
  }