1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Maru [420]
3 years ago
10

I have a class named Counter. In this class I have a synchronized method called countRange(). This method prints out a count in

the range from the minimum to the maximum values stored by the Counter class attributes. Please implement the body of the main() method in Test class to instantiate and start two threads that invoke countRange() method. You can use either named or anonymous Thread instances. Don't forget to make a call to start() method in each thread. What I am asking you to do is similar to what Stopwatch examples in the "Multi-threading and concurrent programming" lecture module showed.
Please only include the code inside the main() method into your answer.
Below is the implementation of Counter class and the shell of the main() method in Test class:
import java.lang.*;
class Counter {
private int min;
private int max;
Counter(int min, int max){
this.min = min;
this.max = max;
}
synchronized public void countRange() {
for(int i = this.min; i <= this.max; i++){
System.out.println(i);
}
}
}
public class Test {
public static void main(String[]args) {
// your implementation goes here
}
}

Computers and Technology
1 answer:
lesya [120]3 years ago
6 0

Answer:

Following are the code to this question:

Counter T = new Counter(1, 100); //creating Counter class object and call its parameterized constructor        

Thread T1 = new Thread(new Runnable()  //creating Thread object T1.

{            

   public void run() //define run method

   {                

       T.countRange(); //call countRange method    

   }          

});    

Thread T2 = new Thread(new Runnable()  //creating another object "T2" of Thread.

{            

   public void run() //define run method

   {                

       T.countRange();           //call countRange method

   }      

});    

T1.start(); //start Thread T1    

T2.start(); //start Thread T2    

Explanation:

Description of the above code as follows:

  • In the given code, inside the main method the Counter class object "T" is created, that calls its parameterized constructor, which accepts two integer value that is "1 and 100".  
  • In the next step, thread class object T1 and T2, is created, which uses run method, in which it called the countRange method inside the method a for loop is declared that prints value between parameter value.  
  • In the last step, the start method is called, which uses the run method to call countRange method.  
  • For full program code please find the attachment.

You might be interested in
A red wavy line under a word means _____. a change has been made in the text a new word was inserted in the document there is a
zloy xaker [14]
Hi there!

The correct option is C. <span>there is a spelling mistake. The red wavy line indicates that a word was spelled incorrectly, sometimes though this function does not recognize the word it can mark it as incorrect even when it is not, in which case you can right-click the marked word and add it to your computer's internal word dictionary. Right-clicking an incorrectly spelled word will also give a short list of words that are similar to the one you are trying to spell, clicking on one of the given words will automatically change the marked word to the one you chose.

-Your friend, ASIAX</span>
7 0
4 years ago
Read 2 more answers
Which of the following statement is False? 1 point Context free language is the subset of context sensitive language Regular lan
alisha [4.7K]

Answer:

Context-sensitive language is a subset of context-free language

Explanation:

Considering the available options, the statement that is considered wrong is "Context-sensitive language is a subset of context-free language."

This is because generally every regular language can be produced through the means of context-free grammar, while context-free language can be produced through the means of context-sensitive grammar, and at the same time, context-sensitive grammars are produced through the means of Recursively innumerable.

Hence, the correct answer in this correct answer to the question is the last option *Context-sensitive language is a subset of context-free langage

3 0
3 years ago
Who is affected by electronuc theft of a song ?
Sonbull [250]
I would have to say the artist.
simply because the artist or publisher does not receive any income on their product. 
7 0
4 years ago
Read 2 more answers
Which would be the most appropriate way to estimate -6.1(0.22)? Check all that apply.
Sergeu [11.5K]

Answer:

A.Use rounding to get -6(0.2), and then multiply. and D. use front end estimation to get -6(0.2), and multiply. and B.

Explanation:

just took the test

7 0
3 years ago
Read 2 more answers
State three differences between a hard drive and a pen drive​
ExtremeBDS [4]

Answer:

A hard drive is what on your computer stores the operating system and all of the files you download. A pen drive (USB DRIVE) is a portable drive used for storing files that you can plug into computers with usb drive ports and transfer that data over to the computer through the USB Drive and you can also copy data onto the USB Drive from a computer and transfer it to other computers.

Explanation:

Computer Technician

7 0
4 years ago
Other questions:
  • SI TENGO: ¿R = 255, G0 =, B = 0, QUE COLOR OBTENGO?
    14·1 answer
  • Write down a recurrence relation for this version of QuickSort, and solve it asymp-totically. Show your work. Assume that the ti
    13·1 answer
  • You can apply bold, italic, and underline styles to text. But why is it a good idea to use underline sparingly?
    13·2 answers
  • 5. Drawing Conclusions If you were a person in
    10·1 answer
  • What are some good websites i can use to test my knowledge?
    11·2 answers
  • In its simplest form, the __________ has two columns: the first column lists every computer and device in the network, while the
    15·1 answer
  • Enum Digits {0, 1};
    10·1 answer
  • Mac and PC .Which one is better for professional users, and why
    6·1 answer
  • After separating from Mexico, Texas passed laws that made it harder for slave owners to _____________ slaves.
    12·2 answers
  • My phone takes forever to load the ads, does anyone else have this problem? Is there a way to fix it? I’ve tried getting another
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!