Java

Topics: Rush Limbaugh, American political pundits, Ann Coulter Pages: 4 (762 words) Published: January 23, 2015
In the long distant future, in the year 2016, the cable news empire has fallen, and former talking heads have stooped to running for political office. In fact, five former talk show stars are running for President of the United States, and locked in a close race. 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 collection = new Queue();
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%...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Java Essay
  • Java Javascript Essay
  • Comparison of Java, Javascript, Java Applets and Java Beans Essay
  • Java Project Essay
  • Java Ring Essay
  • Java Applets Essay
  • Java vs. C++ Essay
  • Essay on Java Cis Assignment 1

Become a StudyMode Member

Sign Up - It's Free