1. Engineering
  2. Computer Science
  3. i need this requirement added to my current java code...

Question: i need this requirement added to my current java code...

Question details

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;

}

}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution