public class Stapler { // class constants private final static int MAX_NUMBER_STAPLES = 100; // object attributes private int numberStaplesLeft = 0; // Stapler(): default constructor public Stapler() { this(0); } // Stapler(): specific constructor public Stapler(int n) { this.setNumberStaples(n); } public void setNumberStaples(int n) { this.numberStaplesLeft = n; } // empty(): remove all staples from the stapler public void empty() { this.setNumberStaples(0); } // punch(): use up a stapler public void punch() { this.removeStaples(1); } // numberLeft(): report the number of staples in the Stapler public int getNumberStaples() { return this.numberStaplesLeft; } // toString(): produce a representation of the state of the Stapler public String toString() { String result = "Stapler: [ " + this.getNumberStaples() + " ]"; return result; } // refill(): fully load stapler public void fill() { this.setNumberStaples(Stapler.MAX_NUMBER_STAPLES); } public void addStaples(int increment) { int n = this.getNumberStaples(); this.setNumberStaples(n + increment); } public void removeStaples(int decrement) { int n = this.getNumberStaples(); this.setNumberStaples(n - decrement); } public Object clone() { int n = this.getNumberStaples(); Stapler duplicate = new Stapler(n); return duplicate; } public void takeStaples(Stapler s) { int n1 = this.getNumberStaples(); int n2 = s.getNumberStaples(); int total = n1 + n2; n1 = Math.min(this.MAX_NUMBER_STAPLES, total); n2 = total - n1; this.setNumberStaples(n1); s.setNumberStaples(n2); } }