Question
I have completed this exercise but my input is output is : input Data length: 6488665, instead of Input Data length: 6488666, could anyone help
I have completed this exercise but my input is output is : input Data length: 6488665, instead of Input Data length: 6488666, could anyone help me redo and explain what I have done wrong? I pasted the exercise below and what is requested. Thank you
WHAT DO I NEED TO DO
Create 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 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 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 name for this thread as Thread_
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. . Using the P01_URLDemo as an example, read the contents of the URL (http://norvig.com/big.txt) 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 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_a running
Thread Thread_b running
Thread Thread_c running
Thread Thread_d running
Thread Thread_e running
Thread Thread_f running
Thread Thread_g running
Thread Thread_h running
Thread Thread_i running
Thread Thread_j running
Thread Thread_k running
Thread Thread_l running
Thread Thread_m running
Thread Thread_n running
Thread Thread_o 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 [] 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 [, , , , ] Thread_a is adding , Cumulative Results are [, , , , , ] Thread_m is adding , Cumulative Results are [, , , , , , ] Thread_e is adding , Cumulative Results are [, , , , , , , ] Thread_z is adding , Cumulative Results are [, , , , , , , , ] Thread_s is adding , Cumulative Results are [, , , , , , , , , ] Thread_y is adding , Cumulative Results are [, , , , , , , , , , ] Thread_c is adding , Cumulative Results are [, , , , , , , , , , , ] Thread_h is adding , Cumulative Results are [, , , , , , , , , , , , ] Thread_f is adding , Cumulative Results are [, , , , , , , , , , , , , ] Thread_b is adding , Cumulative Results are [, , , , , , , , , , , , , , ] Thread_n is adding , Cumulative Results are [, , , , , , , , , , , , , , , ] Thread_x is adding , Cumulative Results are [, , , , , , , , , , , , , , , , ] Thread_w is adding , Cumulative Results are [, , , , , , , , , , , , , , , , , ] Thread_p is adding , Cumulative Results are [, , , , , , , , , , , , , , , , , , ] Thread_r is adding , Cumulative Results are [, , , , , , , , , , , , , , , , , , , ] Thread_v is adding , Cumulative Results are [, , , , , , , , , , , , , , , , , , , , ] Thread_u is adding , Cumulative Results are [, , , , , , , , , , , , , , , , , , , , , ] Thread_q is adding , Cumulative Results are [, , , , , , , , , , , , , , , , , , , , , , ] Thread_i is adding , Cumulative Results are [, , , , , , , , , , , , , , , , , , , , , , , ] Thread_j is adding , Cumulative Results are [, , , , , , , , , , , , , , , , , , , , , , , , ] Thread_o is adding , Cumulative Results are [, , , , , , , , , , , , , , , , , , , , , , , , , ]
Alphabet Count = 5079398
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started