Question: I need help to solve this exercise, I have done the following code, I think the LongTask is wrong. I have attached images below that

I need help to solve this exercise, I have done the following code, I think the LongTask is wrong. I have attached images below that explain what I need to solve/ accomplish. Any help would be appreciated. Thank you

Results Entry:

// public class named ResultsEntry

public class ResultsEntry {

// set instance private variables, such as count (int) and target (char)

private int count;

private char target;

// single constructor with the two values

public ResultsEntry(int count, char target) {

this.count = count;

this.target = target;

}

// get methods for the two variables

public int getCount() {

return this.count;

}

public char getTarget() {

return this.target;

}

// public string that returns the method

public String toString() {

String returnValue;

returnValue = "";

return returnValue;

}

}

Shared Results:

import java.util.ArrayList;

public class SharedResults {

// private instance varriable - results (ArrayList of ResultsEntry type)

private ArrayList results;

// set a default constructor that initializes the above data result

public void SharedResult() {

this.results = new ArrayList();

}

//

public synchronized void addToResults(ResultsEntry entry) {

System.out.printf("%s is adding %s, ", Thread.currentThread().getName(), entry);

results.add(entry);

System.out.printf(" Cumulative Results are %s ", results);

}

public synchronized long getResult() {

long sum = 0;

for (ResultsEntry entry : results) {

sum += entry.getCount();

}

return sum;

}

}

Long Task:

public class LongTask extends Thread {

private SharedResults sharedData;

private StringBuffer inputData;

private char target;

public LongTask(SharedResults r, StringBuffer buf, char target) {

super("Thread_" + target);

sharedData = r;

inputData = buf;

this.target = target;

}

public void run() {

int count = 0;

for (int index = 0; index

if (inputData.charAt(index) == target)

count++;

}

ResultsEntry e = new ResultsEntry(this.target, count);

sharedData.addToResults(e);

}

}

I need help to solve this exercise, I have done the followingcode, I think the LongTask is wrong. I have attached images belowthat explain what I need to solve/ accomplish. Any help would be

C. d. 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. 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) 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_ 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. PST 99- Using the P01_URLDemo as an example, read the contents of the URL (httpzltnorvigcomtbigtxt) 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. Create the SharedResults object and assign it to a variable. 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', '2', respectively. Start the respective thread after creating each one. Wait for all the threads to complete using the join method Print the result from the shared object Sample Output: Different runs of the program will produce the output in different sequences, but the final result would be the same. Input Data length: 6488666 Thread Thread Thread Thread Thread Thread Thread Thread Thrnnd Thread_a running Thread_b running Thread_c running Thread_d running Thread_e running Thread_f running Thread_g running Thread_h running Thrnnd i Funninn Thread Thread_m running Thread Thread_n running Thread Thread_u running Thread Thread_p running Thread Thread_q running Thread Thread_r running Thread Thread_s running Thread Thread_t running Thread Thread_u running Thread Thread_v running Thread Thread_w running Thread Thread_x running Thread Thread_y running Thread Thread_z running Thread_k is adding , Cumulative Results are [J Thread_l is adding , Cumulative Results are [, ] Thread_g is adding , Cumulative Results are [, , ] Thread_t is adding , Cumulative Results are [, , , ] Thread_d is adding , Cumulative Results are [, , , , J Thread_a is adding , Cumulative Results are [, , , , , J Thread_m is adding , Cumulative Results are [, , , , , , J Thread_e is adding , Cumulative Results are [, , , , , , , ] Thread_z is adding , Cumulative Results are [, , , , , , , , J Thread_s is adding , Cumulative Results are [, , , , , , , , , ] Thread_y is adding , Cumulative Results are [, , , , , , , , , , J Thread_c is adding , Cumulative Results are [, , , , , , , , , , , ] Thread_h is adding , Cumulative Results are [, , , , , , , , , , , , ] _______________Ihaad__is_addiaa_i__l225h___________________________________________________________ Part1 (100 points) Create a package named c3520.hw6.pan'1. 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 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 gefResult 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 SharedResuIts), inputData (of type SfringBuffer), 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_

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!