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
Write a Java class called BankAccount (Parts of the code is given below), which has two private fields: name (String) and balanc
NemiM [27]

Answer:

Here is the Bank Account class:

public class Bank Account {   //class definition

   private String name;  //private String type field to hold name

   private double balance;    // private double type field to hold balance

    public Bank Account(String name, double balance) {  // parameter constructor that takes

//this keyword is used to refer to the data members name and balance and to avoid confusion between name, balance private member fields and constructor arguments name, balance

 this.name = name;  

 this.balance = balance;  }    

   public void deposit(double amount) {   //method to deposit amount

               balance = balance + amount;     }    // adds the amount to the account causing the current balance to increase

   public void withdraw(double amount) {  //method to withdraw amount

 balance = balance - amount;   }   //subtracts the amount causing the current balance to decrease

    public String toString() {  // to display the name and current balance

              return name + " , $" + balance; }  } //returns the name and the current balance separated by a comma and dollar

Explanation:

The explanation is provided in the attached document due to some errors in uploading the answer.

3 0
3 years ago
Seth would like to make sure as many interested customers as possible are seeing his business’s website displayed in their searc
GenaCL600 [577]

Answer:

Hi! Make sure that the website has a few things. Proper Keywords, the pages have the proper tags, a form on the website, contact information, CIty State, Etc., Then a phone number. Social media icons that link properly to the social media pages.

Explanation:

5 0
3 years ago
PLEASE HELP<br>what are some benefits of using graphic on web page?​
qwelly [4]

Images help tell a story where describing with words is either too lengthy, or practically impossible. For instance, you could have a map of a location and various arrows and other markings to describe movements of troops during a battle of the civil war. This is one example of many that you could have as an image on a website. Describing the troop movements with words only may be really difficult to do. Plus many people are visually oriented learners, so they benefit with images every now and then. Of course, it's best not to overdo things and overload the site with too many images. A nice balance is needed.

5 0
2 years ago
• The technical support department at your company has informed you that you will be receiving a new computer within the next we
alexdok [17]
1) back up your data
2) delete any personal information
3) clear cookies, browsing data, and saved passwords
4) restore any settings you may have changed to original settings
6 0
3 years ago
Please help What two Boolean operators can you use to narrow your search results?
daser333 [38]

Answer:

if and and not and or ans all

7 0
3 years ago
Other questions:
  • Problem 1 (Authentication): Consider the following authentication protocol, which uses a classical cryptosystem. Alice generates
    5·1 answer
  • Forms are used to a provide a more user-friendly way to work with data in tables
    14·1 answer
  • Enter a formula in cell b7 to calculate the average value of cells b2:b6
    13·1 answer
  • How can a user view the options for Junk E-mail?
    11·2 answers
  • In the event you get pulled over for a traffic stop, describe the situation from the police officer's perspective and list at le
    6·2 answers
  • Which of the following is true of how computers represent numbers?
    9·2 answers
  • What is a Forloop and what is it used for?
    7·2 answers
  • Which option is created specifically for giving a slide presentation in front of an audience and works when the speaker is utili
    14·1 answer
  • Answer This One Question Right For Brainliest
    10·1 answer
  • Which insert image option allows a user to compile, modify, and add captions to images?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!