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
____ [38]
3 years ago
9

Write a class called Counter that represents a simple tally counter, which might be used to count people as they enter a room. T

he Counter class should contain a single integer as instance data, representing the count. Write a constructor to initialize the count to zero. Write a method called click that increments the count and another method called get Count that returns the current count. Include a method called reset that resets the counter to zero. Finally, create a driver class called CounterTest that creates two Counter objects and tests their methods.
Computers and Technology
1 answer:
Sonja [21]3 years ago
4 0

Answer:

Code is in java

Explanation:

Code is self explanatory, added come comments to explain more about the code.

public class CounterDriver {

   public static void main(String[] args){

       // Creating counter first object

       Counter counter1 = new Counter();

       //performing 2 clicks

       counter1.click();

       counter1.click();

       // displaying counter 1 click count

       System.out.println("Total Number of counter1 clicks :"+counter1.getCount());

       // resetting counter 1 click count

       counter1.reset();

       // again displaying click count which will be 0 after reset

       System.out.println("Total Number of counter1 clicks :"+counter1.getCount());

      // Same operation goes with counter 2  

       // the only difference is that it performs 3 clicks

       Counter counter2 = new Counter();

       counter2.click();

       counter2.click();

       counter2.click();

       System.out.println("Total Number of counter2 clicks :"+counter2.getCount());

       counter2.reset();

       System.out.println("Total Number of counter2 clicks :"+counter2.getCount());

   }

}

class Counter{

   int count;

// defining constructor which will initialize count variable to 0

   public Counter(){

       this.count=0;

   }

// adding click method to increment count whenever it's called

   public void click(){

       this.count++;

   }

// getCount method will return total count

   public int getCount(){

       return this.count;

   }

// reset method will set count to 0

   public void reset(){

       this.count = 0;

   }

}

You might be interested in
After stating your thesis, follow up by demonstrating the importance of the topic, and explain why the audience or future audien
bearhunter [10]

Answer: audience relevance

Explanation:

Most importantly when stating a thesis we should show and present how the work in the thesis is relevant to the audience. In this way we would be able to connect our research work more to the people and the audience. We should be able to state how our work is going to benefit them, what the people should do in this regard and all the dos and don't must be mentioned clearly while stating our thesis.

4 0
3 years ago
Explain why living things store energy in lipids instead of in carbohydrates
Vedmedyk [2.9K]
Lipids are fat and carbohydrates are used to provide your body with energy so they are always being used
7 0
3 years ago
Does anybody know how to unlock websites from school computer
Grace [21]

Answer:

yes go to settings then apps

Explanation:

that's how I did mines

8 0
2 years ago
According to the amendment, the federal government has only those powers specified by the Constitution. These powers include the
Oxana [17]

Answer:

please where's the question

7 0
2 years ago
Taylor volunteered as a computer support specialist for his university's online library. Which part of his resume should include
Sophie [7]
 it would be experience 
<span />
8 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following is another name for cinematographers? (Select all that apply). lighting specialists production manager di
    8·1 answer
  • What are the meaning master files<br>​
    8·1 answer
  • Routing connects different network segments and decides where __________are sent to
    7·1 answer
  • In his article “is google making up stupid” Nicholas Carr uses a metaphor to suggest that
    11·2 answers
  • Where can i watch bnha movie 2 online for free, with no sign up or pay?
    6·2 answers
  • BRAINLEST AND 20 POINTS! Most GUls provide all of the following except
    6·2 answers
  • Lin wants to play an online game with her friends. She read the description of the game and knows it contains several features w
    12·1 answer
  • ¿Cuál es la capacidad pulmonar del hombre y la mujer?
    11·1 answer
  • When you create a new database using --------- , the database includes prebuilt tables and forms which you can populate with dat
    15·1 answer
  • Suppose that you have declared a numeric array named numbers, and two of its elements are numbers[1] and numbers[4]. You know th
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!