Write a class that implements this interface while not


Assignment

(a) In the slides and textbook, one of the examples features a class for counting up. An interface which defines this functionality is given below:

public interface IncrementCounter {

//Increments the counter by one.

void increment();

//Returns the number of increments since creation.

int tally();

//Returns a string representation that counts number of increments and the ID of the counter.

String toString();

}

Write a class that implements this interface while not using any number type member variables (e.g., int, float, etc). The class should be named AnotherCounter and have a constructor that takes a String parameter to store as an ID.

Your answer should include only the class you have written.

(b) (Assume the integer-based Counter class in the book also implements the IncrementCounter interface.)

From the perspective of someone choosing to use AnotherCounter versus Counter in a larger program, is there a difference? Explain. Consider both a functionality standpoint, and a performance standpoint.

Solution Preview :

Prepared by a verified Expert
Computer Engineering: Write a class that implements this interface while not
Reference No:- TGS02926417

Now Priced at $15 (50% Discount)

Recommended (95%)

Rated (4.7/5)