Last active
August 29, 2015 14:03
-
-
Save hilda8519/02d64d36b92f031f3c87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Animal { | |
String type; | |
Date arrive; | |
String name; | |
} | |
public class Cats extends Animal{ | |
public Cats(String name){ | |
this.name=name; | |
type="cats"; | |
} | |
} | |
public class Dogs extends Animal{ | |
public Dogs(String name){ | |
this.name=name; | |
type="dogs"; | |
} | |
} | |
public class AnimalQueue{ | |
Linkedlist<Dog> dogs=new LinkedList<Dog>(); | |
LinkedList<Cat> cats=new LinkedList<Cat>(); | |
private int order=0; | |
public void enqueue(Animal a){ | |
a.setOrder(order); | |
order++; | |
if(a instanceof Dog) | |
{dogs.addLast((Dog) a); | |
} | |
else (a instanceof Cat){ | |
cats.addLat((Cat)a); | |
} | |
public Animal dequeue(){ | |
if(dog.size()==0){ | |
return dequeueCats(); | |
} | |
else(cats.size()==0){ | |
return dequeueDogs(); | |
} | |
Dog dog=dogs.peek(); | |
Cat cat=cats.peek(); | |
if(dog.isOlderThan(at)){ | |
return dequeueDogs(); | |
} | |
else{ | |
return dequeueCats(); | |
} | |
public Dog dequeueDogs(){ | |
return dogs.poll(); | |
} | |
public Cat dequeueCats(){ | |
return cats.poll(); | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment