public class Balloon { protected int maxRadius; protected int radius; protected boolean popped; protected Balloon() { maxRadius = 0; radius = 0; popped = false; } /** * Creates a balloon with given maximum radius; initially, the balloon is deflated (radius is zero) and is not popped. * @param max maxium radius of the balloon */ public Balloon(int max) { maxRadius = max; radius = max; popped = false; } public boolean equals(Balloon b) { boolean same = false; if (maxRadius == b.maxRadius && radius == b.radius && popped == b.popped) { same = true; } return same; } public String toString() { String result = "maxRadius: "+Integer.toString(maxRadius)+ " radius: "+Integer.toString(radius); if (popped) { result+=" popped"; } else { result+=" not popped"; } return result; } /** * Returns the current radius of this balloon */ public int getRadius(){ return radius; } /** * Increases the radius of the balloon by a specified amount causing it to pop if the radius is increased beyond the maximum radius (this method has no effect if the balloon is already popped). * @param amount the amount by which the to increse the radius */ public void inflate(int amount){ radius+=amount; } /** * Deflates the balloon without popping it (a deflated balloon has radius zero).0 */ public void deflate(){ maxRadius = 0; } /** * Determines whether this balloon is popped. */ public boolean isPopped(){ return popped; } /** * Pops the balloon (a popped balloon has radius zero). */ public void pop(){ radius = 0; } }