Create a class named ResultsEntry

Assignment Help Other Subject
Reference no: EM132411998

CS520 Assignment -

You are strongly encouraged to add comments into your program!

Given a large text file, the goal of this project is to count how many times each alphabet character appears in the text file. The text file will be converted to lowercase during the reading process. The program will create 26 threads. The contents of text file read is shared between the 26 threads. The first thread will count the number of a's, the second thread will count the number of b's, and so on.

All the threads also share a Results object. Each thread will contribute its own result to the shared Results objects.

Create a new Java Project in Eclipse named HW6_lastName and complete the following requirements based on the Threads.

Part 1 -

Create a package named cs520.hw6.part1. Using this package, create the following classes.

1. Create a class named ResultsEntry as follows:

a. The instance private variables - count (int) and target (char)

b. A single constructor with the two values

c. Public get methods for the two variables

d. Public toString method that returns a string in the format <target,count>

2. Create a class named SharedResults as follows:

a. A private instance variable - results (ArrayList of ResultsEntry type)

b. A default constructor that initializes the above data structure. c. A void addToResults method which takes the given ResultsEntry argument and adds it to the end of the shared results. This method then prints to the console the name of the current thread, the entry it added, and the shared results data structure. Handle the synchronization issue with this method.

d. The getResult method with no arguments which returns the sum of the count entry values in the shared results data structure. Handle the synchronization issue with this method.

3. Create a class named LongTask that extends the Thread class.

a. The instance (or member) private variables - sharedData (of type SharedResults), inputData (of type StringBuffer), and target (of type char)

b. A single constructor which takes the above three arguments and stores them in the instance values. Also, create a name for this thread as Thread_<target>

c. In the run method, use a loop to go over char chacacter in the inputData and count the number of occurrences of target. After the loop is done, create a ResultsEntry object with this count and the target character, and invoke the addToResults method of the shared results object.

4. Create a Test class to test the following functionality in its main method.

a. Using the P01_URLDemo as an example, read the contents (attached) into a StringBuffer object. After reading each line from the network, convert it to lower case and append to the StringBuffer. This will be the input data that is shared for each thread.

b. Create the SharedResults object and assign it to a variable.

c. Create 26 LongTask objects using an array of size 26. Each LongTask object is responsible to counting the occurrences of the characters 'a', 'b', 'c', ..., 'z', respectively. Start the respective thread after creating each one.

d. Wait for all the threads to complete using the join method.

e. Print the result from the shared object.

Part 2 -

Create a package named cs520.hw6.part2. Modify the above program using the wait/notifyAll features. When a thread tries to contribute its results to the shared data, and if it is not this thread's turn, it has to wait. When it is the thread's turn, its contributing result is added to the shared results and all other threads are notified. Thread_a will be first, Thread_b will be second, and so on. Suggested modifications to Part1 code are shown below.

1. SharedResults class

a. addToResults method takes two arguments, the calling thread's turn and the contributing result that needs to be added to the shared results. Implement the wait and notifyAll functionality in this method. Print to the console the thread's turn, the name of the current thread, the value it added, and the shared results data structure. Handle the synchronization issue with this method. Use the size of the data structure to determine if it is the calling thread's turn.

2. LongTask class

a. Add the turn (integer) instance variable

b. Modify the constructor to take care of this additional argument.

c. In the run method, after the loop of computation is done, invoke the addToResults method of the shared object and provide this thread's turn and its this accumulated ResultsEntry.

3. Test class

Provide the turn for each LongTask thread when invoking the constructor. Thread_a's turn is 0, Thread_b's turn is 1, and so on.

Attachment:- Assignment File.rar

Reference no: EM132411998

Questions Cloud

What areas of emotional management would you like to improve : What areas of emotional management would you like to improve? How do you think this will help you as a leader? How might storytelling be beneficial to you.
Discuss a no-fault medication error plan : You are the CHRO of Big City Medical Center. The CNO of BCMC comes to meet with you to discuss a no-fault medication error plan. Nursing literature shows.
ANTY 101 - Anthropology and the Human Experience Assignment : ANTY 101 - Anthropology and the Human Experience Assignment - Field Reflection Paper, Homework Help, Montana State University, USA
Describe the advantages and the disadvantages of arbitration : Create a Mind Map using a tool such as Popplet, Mindmeister, GoConqr, or a Microsoft Word document in which you do the following: Assess three advantages.
Create a class named ResultsEntry : CS520 Assignment - Create a class named ResultsEntry as follows: The instance private variables - count (int) and target (char)
Write about what locations are a possibility and why : Need one page double spaced paper using the Houston chronicle business section if able, write about what locations are a possibility and why
BUSN20031 - Social Innovation Assignment : BUSN20031 - Social Innovation Assignment Help and Solution - Central Queensland University, Australia. What are ways to make your business more socially engaged
PDE4910 Logistics and Supply Chains Assignment : PDE4910 Logistics and Supply Chains Assignment Help and Solution - Middlesex University, UK. Supply Chain Management Individual Report Assignment
Write a report about the success or failure of new product : Write a report about the success or failure of new product/service introduced within the most recent years. Product or service: JIO

Reviews

Write a Review

Other Subject Questions & Answers

  Examples of numerous views of the truth

Crtically discuss  examples of numerous views of the truth for the same reality situation? Why should we understand the transition from personal values to group values?

  Two solutions of glucose

A membrane separates two solutions of glucose. The outside concentration of 5 mM and the inside has a concentration of 20 mM.

  Analyze which cost-cutting options you selected

Analyze which cost-cutting options you selected and why.Analyze which loan option you selected and why.Analyze the outcome of your capital shortage decision.

  How well a test captures what it intends to measure

___ refers to how well a test captures what it intends to measure. A formula that guarantees a correct solution to certain kinds of problems is known as a(n)___

  Discuss the findings from the laboratory blood tests

Which of the following findings from the laboratory blood tests has to be of greatest concern and why

  Describe the history of the global health data exchange

Describe the history and development of the Global Health Data Exchange (GHDx), and explain why it was formed. Include the types of services it provides around the world.

  Write a page letter to an elected official

Write a two page letter to an elected official describing the impact of the health issue on your target population.

  Process and viewpoint of a client

She said she believed in helping others, however she stopped doing this last year because she feels that it feeds into the corrupt system of welfare.

  Identify other archetypes within the story

Explain the conflicts between personal desires and community responsibility represented in the myth and the contemporary story. Relate these to the conflicts and choices with which ordinary humans struggle. Explain why these human conflicts retain..

  Prepare a detailed recommendation to your facility manager

Prepare a detailed recommendation to your facility manager identifying what the company needs to do to bring the organization.

  How laboratory analysis helps archaeologists

Overview For this discussion, we examine archaeological evidence (e.g.artifacts and ecofacts) and how that contributes to our understanding of how cultures.

  Promote human rights or uphold freedoms

Democracy, to some extent, lets citizens select their leaders and establish laws. But democracy does not guarantee that those citizens, leaders, or laws will promote human rights or uphold freedoms.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd