Question
Create a class named ResultsEntry containing the following:Private instance variablesnamedcount(int) and target(char)A single constructor with the two valuesPublic getmethods for the two variablesA public toString()method
Create a class named ResultsEntry containing the following:Private instance variablesnamedcount(int) and target(char)A single constructor with the two valuesPublic getmethods for the two variablesA public toString()method that returns a string in the format target,count
and this is my code
public class ResultEntry { //creating the private instance private int count; private char target; //creating the default constructor public ResultEntry() { } //Creating the constructor with two values public ResultEntry(int count, char target) { this.count = count; this.target = target; } //Creating public get methods for the two variables public int getCount() { return this.count; } public char getTarget() { return this.target; } //Creating toString method public String toString() { return "" + target + count; }
} Create a class named SharedResults containing the following:Private instance variable named resultsof ArrayList
this is my code
import java.util.ArrayList;
import java.util.List;
public class SharedResults {
//Create the private instance as an ArrayList
private List
//Create the default constructor
public SharedResults() {
}
//Create void method ToResults
public synchronized void ToResults(ResultsEntry resultEntry) {
//start try/catch
try {
//add the argument to results
this.results.add(resultEntry);
/*
* printing the name of the current thread
* the entry it added and the results data Structure
*/
System.out.println("Thread " + results + " " + resultEntry+ "" + this.results);
}catch(InterruptedException e) {
e.printStackTrace();
}
}
//creating public method getResult
public synchronized int getResult() {
int sum =0;
for (int i=0; i<=results.size();i++) {
results.get(i);
return sum += results.get(i) ;
}
Create a class named LongTaskthat extends the Threadclasscontaining the following:Private instance variablessharedData(of type SharedResults), inputData(of type StringBuffer)and target(of type char) Constructor thattakes three arguments and stores them in the instance variables.It should alsocreate a name for this thread as Thread_
this is the code
public class LongTask extends Thread { //Create private instance variables SharedData, inputData, target private SharedResults sharedData; private StringBuffer inputData; private char target; //create constructor with three arguments public LongTask(SharedResults sharedData, StringBuffer inputData, char target) { this.sharedData = sharedData; this.inputData = inputData; this.target = target; //it should also create a name for this thread as Thread_ } I stuck at the for loop I didn't know what to do and what is this it should also create a name for this thread as thread_ here I lost and I couldn't complete it?? any help??
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