Question: Java write the class Counter Comments about the class Counter: Methods click and reset do not return anything. There is no setter method. Also include

Java write the class Counter

Comments about the class Counter:

  • Methods click and reset do not return anything.
  • There is no setter method.
  • Also include a toString method.

The tester is shown below:

public class CounterTest {

public static void main(String[] args) { Counter c1 = new Counter(); Counter c2 = new Counter();

System.out.println("Counter 1: " + c1 + " Counter 2: " + c2);

c1.click(); c1.click(); c1.click(); c1.click(); c1.click();

c2.click(); c2.click(); c2.click();

System.out.println("Counter 1: " + c1 + " Counter 2: " + c2); System.out.println("Sum: " + (c1.getCount()+c2.getCount()));

c1.reset();

System.out.println("Counter 1: " + c1 + " Counter 2: " + c2); } }

Sample output:

Java write the class Counter Comments about the class Counter: Methods click

> run Counter Test Counter 1: 0 Counter 2: 0 Counter 1: 5 Counter 2: 3 Sum: 8 Counter 1: 0 Counter 2: 3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!