Question: I need this requirement added to my current JAVA code. In addition, add a button to the tally counter that allows an operator to undo

I need this requirement added to my current JAVA code.

In addition, add a button to the tally counter that allows an operator to undo an accidental button click. Provide a method, public void undo() that simulates such a button. As an added precaution, make sure that the operator cannot click the undo button more often than the count button.

public class Counter

{

//Attributes

private int value; //instance variable

private int limit;

//Behavior

public int getValue()

{

return this.value;

}

public void setLimit(int maximum) {

this.limit = maximum;

}

public void count() {

if(this.value== this.limit) {

System.out.println("Limit exceeded");

}

else {

this.value = this.value +1;

}

}

public void undo() {

if(this.value>0) {

this.value -=1;

}else {

this.value=0;

}

}

public void reset() {

this.value =0;

}

}

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!