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

  Importance of the issue to public health

Briefly describe what is currently known about this issue and the population group(s) most likely affected - Choose a public health issue that is of interest

  Describe the dynamics of the interview

Describe the dynamics of the interview, including the relationship between the interviewer and the respondent, the effects of the interview location, and any preconceived expectations from the interviewer and the respondent.

  Frances has plenty of time to devote to her painting

Frances has plenty of time to devote to her painting.

  Importance of motivation in education for young children

Include the following for both the Birth to Age 5/Pre-K and K to Age 8/Grade 3 groups: Importance of motivation in education and learning for young children.

  What is sexual implication of the phrase souse with spray

How can the woman splash in the water and also "stay stock still" in her room? What is the sexual implication of the phrase "souse with spray"? What other sexually charged language is there in these lines?

  Briefly discuss the goal of a precis

This quarter, you will write four précis (pronounced "pray-see" in both its singular and plural forms). The goal of a précis is to faithfully reproduce.

  How does this affect environmental policies today

How do you think the tragedy of the commons model describes our world today?

  Think most significantly influence youth today

What historical and/or demographic trend do you think most significantly influence youth today?

  Determine whether the law and the anas standards support

Consider what action you would take if you were Lena and why. Determine whether the law and the ANA's standards support or conflict with that action.

  Discuss about the militarization of police

Select a position on the militarization of police. Are you in support of police militarization or against police militarization?

  Why were the dutch able to replace the portuguese

In the Dutch Golden Age, markets were more fully developed in the United Provinces than anywhere else in Europe. What kinds of markets existed?

  Describe the layout of cuzco and its architecture

Describe the layout of Cuzco and its architecture (including some of its main structures), and explain how it was connected to the Inca empire at large.

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