Your task is to design and implement a set of classes that process a collection of Integer objects, corresponding to votes for each candidate.
The integers are stored in a queue by a driver. In particular, the following code must compile error free and execute correctly on your implementation. You should implement your own generic Queue class. If you borrow code from elsewhere, cite your sources.
public static void main(String[] args) {
Queue<Integer> collection = new Queue<Integer>(); for (int index = 0; index < 10000; index++) { int candidate = ((int) (Math.random() * 10000)) % 5;
Integer integ = new Integer(candidate); collection.enqueue(integ); }
RequestProcessor processor = new
RequestProcessor(collection);
int numberOfThreads = 5;
Thread[] threads = new Thread[numberOfThreads]; for (int index = 0; index < threads.length; index++) { threads[index] = new Thread(processor); threads[index].start(); } try { for (int index = 0; index < threads.length; index++) { threads[index].join(); }
} catch(InterruptedException ie) { ie.printStackTrace(); }
ThreadStatisticsSetup.print();
}
One possible output is:
Tabulator: 1 Count 1137 for candidate Bill
O'Reilly=20.695303967965053%
Tabulator: 1 Count 1077 for candidate Ann
Coulter=19.603203494721516%
Tabulator: 1 Count 1090 for candidate Rachel
Maddow=19.839825263924283%
Tabulator: 1 Count 1094 for candidate Rush
Limbaugh=19.912631962140516%
Tabulator: 1 Count 1096 for candidate Glenn Beck=19.949035311248636%
Tabulator: 2 Count 232 for candidate Bill
O'Reilly=19.414225941422593%
Tabulator: 2 Count 232 for candidate Ann Coulter=19.414225941422593%
Tabulator: 2 Count 243 for candidate Rachel
Maddow=20.334728033472803%
Tabulator: 2 Count 216 for candidate Rush