Answer:
import java.util.*;
public class Q {
public static LinkedList<String> dogs = new LinkedList<String> ();
public static LinkedList<String> cats = new LinkedList<String> ();
public static LinkedList<String> animals = new LinkedList<String> ();
public static void enqueueCats(){
System.out.println("Enter name");
Scanner sc=new Scanner(System.in);
String name = sc.next();
cats.addLast(name);
animals.addLast(name);
}
public static void enqueueDogs(){
System.out.println("Enter name");
Scanner sc=new Scanner(System.in);
String name = sc.next();
dogs.addLast(name);
animals.addLast(name);
}
public static void removeFromQueue(char q,String name){
LinkedList<String> L = new LinkedList<String> ();
switch (q) {
case 'c':
L = cats;
break;
case 'd':
L = dogs;
break;
case 'a':
L = animals;
}
LinkedList<String> tmp = new LinkedList<String> ();
while (!L.isEmpty()){
if(!L.getFirst().equals(name)){
tmp.add(L.getFirst());
}
L.removeFirst();
}
while (!tmp.isEmpty()){
L.add(tmp.removeLast());
}
}
public static void dequeueCats(){
System.out.println("Enter name");
Scanner sc=new Scanner(System.in);
String name = sc.next();
removeFromQueue('c',name);
removeFromQueue('a',name);
}
public static void dequeueDogs(){
System.out.println("Enter name");
Scanner sc=new Scanner(System.in);
String name = sc.next();
removeFromQueue('d',name);
removeFromQueue('a',name);
}
public static void dequeueAnimals(){
System.out.println("Enter name");
Scanner sc=new Scanner(System.in);
String name = sc.next();
removeFromQueue('a',name);
removeFromQueue('d',name);
removeFromQueue('c',name);
}
public static void display(){
System.out.println("animals:");
for (String s : animals)
System.out.print(s);
System.out.println();
System.out.println("cats:");
for (String s : cats)
System.out.print(s);
System.out.println();
System.out.println("dogs:");
for (String s : dogs)
System.out.print(s);
System.out.println();
}
public static void display_choices(){
String [] choices = {"Donate a Cat","Donate a Dog","Adopt a Cat","Adopt a Dog","Adopt Oldest Pet","Exit"};
for (int i=0;i<choices.length ;i++ ) {
System.out.println((i+1)+"."+choices[i]);
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(true){
display_choices();
int choice=sc.nextInt();
switch (choice) {
case 1 :
enqueueCats();
display();
break;
case 2 :
enqueueDogs();
display();
break;
case 3 :
dequeueCats();
display();
break;
case 4 :
dequeueDogs();
display();
break;
case 5:
dequeueAnimals();
display();
case 6 :
System.exit(0);
}
}
}
}