All pastes #757516 Raw Edit

vol

public java v1 · immutable
·published 2007-11-01 12:27 UTC
rendered paste body
public class GrannySmith {  public final static Color color  = Color.GREEN;  public final static String taste = "Delicious";  public final static byte percentPerByte = 4;  public static numApples = 0;    public byte percentEaten = 0;  public boolean rotten = false;  public GrannySmith() {    // Default constructor has all the right values defined already.    // percentEaten was initialized to 0, and rotten was initialized to false.    numApples++; // Tell the world that we made another apple  }  public GrannySmith(byte _percentEaten, boolean _rotten) {    percentEaten = _percentEaten;    rotten = _rotten;    numApples++; // Tell the world that we made another apple  }  /** rot the apple */  public void rot() {    rotten = true;    numApples--; // one less apple to eat :(  }  /** Take a bite out of the apple. If there is more apple to eat, returns true. */  public boolean bite() throws RottenException {     if(rotten) throw new RottenException("This apple is rotten!");    if(percentEaten < 100) {      percentEaten += percentPerByte;      if(percentEaten == 100) numApples--; // one less apple to eat :(    return percentEaten < 100;  }  }