Preview

Java

Satisfactory Essays
Open Document
Open Document
762 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Java
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<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

You May Also Find These Documents Helpful

  • Good Essays

    Honors Discrete Voting Theory Project Part 2 You will be presenting your project on October 17. Conduct your own preference ballot. A. B. C. D. E. F. G. H. I. J. K. L. Determine the winner of the election using the Plurality Method.…

    • 378 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Java

    • 5076 Words
    • 21 Pages

    Explanation: B) Programs are classified as software to differentiate them from the mechanisms of the computer (hardware). Storage and the processor are two forms of hardware while input is the information that the program processes.…

    • 5076 Words
    • 21 Pages
    Good Essays
  • Powerful Essays

    | Hint: Get the contribution per barrel of Mountain Man Light In the second work sheet…

    • 701 Words
    • 3 Pages
    Powerful Essays
  • Good Essays

    Programming

    • 3038 Words
    • 13 Pages

    2. Each of the flowchart segments in Figure 3-35 is unstructured. Redraw each flowchart segment so that it does the same thing but is structured.…

    • 3038 Words
    • 13 Pages
    Good Essays
  • Good Essays

    Java

    • 490 Words
    • 3 Pages

    Write a Java program to demonstrate using bitmaps and bitwise operators to sort and remove duplicates from a file of random phone numbers. Do not confuse the term bitmap used for compressing data into smaller spaces with the bitmap that has come to mean a graphic image.…

    • 490 Words
    • 3 Pages
    Good Essays
  • Good Essays

    “Donnie Darko,” directed by Richard Kelly, starts and ends in the same place: Donnie Darko’s bedroom. Before any other sound is played in the movie, a deep voice is heard saying “wake up,” followed by an eerie and discordant mixture of noises. Already Kelly has set the tone of the movie to be dark, mysterious, and suspenseful. From the beginning of the movie, I was captivated by how a few sounds can create such an ambiance surrounding Donnie’s unusual actions. As Donnie seems to be sleep-walking out of his room, his breath is emphasized to show the irregularity of the situation and his drowsy state of mind, developing the intensity for the scenes to come.…

    • 657 Words
    • 3 Pages
    Good Essays
  • Powerful Essays

    Brannigan Foods

    • 2496 Words
    • 42 Pages

    BRANNINGAN FOOD’S DECLINING SOUPS DIVISION Table of Contents       Executive Summary …Slide 3 Hypothesis …Slide 4 Evidence …Slide 5 Background …Slide 6 Market Report … Slide 7-9  Tipha …Slide 23-25  Mackey … Slide 2628  Chung … Slide 2931  Pugh …Slide 32-34  Analysis of the situation…Slide 1021  Current Market Position …Slide 10-12  Competitive Analysis …Slide 1317  SWOT ……

    • 2496 Words
    • 42 Pages
    Powerful Essays
  • Better Essays

    JAVA

    • 956 Words
    • 4 Pages

    References: Tutorials Point - Simply Easy Learning. (n.d.). Java. Retrieved July 7, 2014, from http://www.tutorialspoint.com/java/java_abstraction.htm…

    • 956 Words
    • 4 Pages
    Better Essays
  • Good Essays

    Java

    • 827 Words
    • 4 Pages

    9. The withholding tax on a weekly salary (let us assume) is computed as follows: 14% of the difference between a person's gross pay and $13 times the number of dependents he or she claims. Read the values for the gross pay and the number of dependents; print the withholding tax.…

    • 827 Words
    • 4 Pages
    Good Essays
  • Powerful Essays

    When only two candidates are involved, there is only one way to count, but when there are more you can choose a variety of methods. The more candidates that are involved the harder it is to determine who the “real” winner is. The “normal” method in the United States is to vote for a single candidate and take the “absolute” winner out of the group of candidates. Dr. Hawthorne introduced a few other methods and showed how in a group of multiple candidates, the way you count matters.…

    • 1893 Words
    • 8 Pages
    Powerful Essays
  • Satisfactory Essays

    Bank

    • 469 Words
    • 2 Pages

    Lab Objectives In this lab we will learn implementation of queue data structure using circular array.…

    • 469 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Key Words in Java

    • 888 Words
    • 4 Pages

    Part of the Java For Dummies Cheat Sheet The 50 Java keywords have specific meanings within the language, so you can’t use the keywords in this table for anything other than their function within Java. And, you can't make up new meanings for the words false, null, and true, either. But for technical reasons, those three words aren't called keywords. Whatever!…

    • 888 Words
    • 4 Pages
    Good Essays
  • Satisfactory Essays

    Thesis on java

    • 314 Words
    • 2 Pages

    This class consists of static utility methods for operating on objects. These utilities include null-safe or null-tolerant methods for computing the hash code of an object, returning a string for an object, and comparing two objects.…

    • 314 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Inroduction to Java

    • 536 Words
    • 3 Pages

    3. An Application and run-time environment – general purpose program that run n any machine where the java run time environment (JRE) is installed.…

    • 536 Words
    • 3 Pages
    Satisfactory Essays
  • Powerful Essays

    The Art and Science of Java

    • 3909 Words
    • 16 Pages

    1. Babbage’s Analytical Engine introduced the concept of programming to computing. 2. Augusta Ada Byron is generally recognized as the first programmer. The U.S. Department of Defense named the Ada programming language in her honor. 3. The heart of von Neumann architecture is the stored-programming concept, in which both data and programming instructions are stored in the same memory system. 4. Hardware is tangible and comprises the physical parts of a computer; software is intangible and consists of the programs the computer executes. 5. The abstract concept that forms the core of computer science is problem-solving. 6. For a solution technique to be an algorithm, it must be • Clearly and unambiguously defined • Effective, in the sense that its steps are executable • Finite, in the sense that it terminates after a bounded number of steps 7. Algorithmic design refers to the process of designing a solution strategy to fit a particular problem; coding refers to the generally simpler task of representing that solution strategy in a programming language. 8. A higher-level language is a programming language that is designed to be independent of the particular characteristics that differentiate computers and to work instead with general algorithmic concepts that can be implemented on any computer system. The higher-level language used in this text is called Java. 9. Each type of computer has its own machine language, which is different from that used in other computers. The compiler acts as a translator from the higher-level language into the machine language used for a specific machine. 10. A source file contains the actual text of a program and is designed to be edited by people. An object file is created by the compiler and contains a machine-language representation of the program. Most programmers never work directly with object files. 11. A syntax error is a violation of the grammatical rules of the programming…

    • 3909 Words
    • 16 Pages
    Powerful Essays