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
When you develop an application using a 3-layer architecture, the layer that provides the user interface is called the _____ lay
alexdok [17]
<span>When you develop an application using a 3-layer architecture, the layer that provides the user interface is called the Presentation layer?</span>
5 0
3 years ago
VI. Differentiate between systems SUIwal unu up
siniylev [52]

Answer:

So in a library u might want to get some reading or homework done the way one can use a computer to improve academic preferences is bye one a computer u can type a essay and look for a book

Explanation:

3 0
3 years ago
After reading passage “the incredible machine” why do you think the article has been titled so?
Vitek1552 [10]
I haven’t read it, but just by the title it was probably talking about an incredible machine that was new to people.
7 0
3 years ago
In two to three sentences, describe how you would move a file.
Ksivusya [100]
First you locate the file you want to move. Then you can click and drag the file to the desired location.
hope this helped
6 0
3 years ago
You typed the word "weather" when you meant to type the word "whether." When will Writer or Word flag this as a misspelling or a
maria [59]

Answer:

It depends on the structure of the sentence.

Explanation:

This will be shown as grammatical mistake because both the spellings are correct. If we write the word weather instead of the whether, Ms word shows the grammatical mistake. This is because, if we want to write the word whether, we should use or in our sentence. Both of these words are comes together.

Example

I will take a leave whether its raining or not.

In above sentence, both whether and or comes together. If we write weather instead of whether it just show the grammatical mistake in the sentence.

4 0
3 years ago
Read 2 more answers
Other questions:
  • Write code that prints: Ready! firstNumber ... 2 1 Run!
    12·1 answer
  • Which of the following are common navigation elements? (Choose all that apply.)
    5·1 answer
  • How many times is the text "Let's have fun with Java." printed when this code snippet is run? int i = 0; do { System.out.println
    10·1 answer
  • PLEASE HELP ASAP!!
    6·2 answers
  • What is a command-line interactive scripting environment that provides the commands for almost any management task in a Windows
    9·1 answer
  • Which is the fastest CPU and why?
    5·1 answer
  • A qué escala está dibujado el plano del Instituto si sabemos que la puerta principal de entrada tiene un ancho 3,40 metros y en
    14·1 answer
  • Sube
    10·2 answers
  • What should Anthony use to determine his available study hours for an upcoming project? LOOK AT THE PICTURE
    8·2 answers
  • A type of user interface that features on- screen objects, such a menus and icons, manipulated by a mouse.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!