// File: Plant.java from the package edu.colorado.simulations // Complete documentation is available from the Plant link in // http://www.cs.colorado.edu/~main/docs/ package edu.colorado.simulations; /****************************************************************************** * A Plant is an Organism with extra methods that * allow it to be eaten. * * Java Source Code for this class: * * http://www.cs.colorado.edu/~main/edu/colorado/simulations/Plant.java * * * @author Michael Main * (main@colorado.edu) * * @version Feb 10, 2016 * * @see Organism ******************************************************************************/ public class Plant extends Organism { /** * Construct a Plant with a specified size and growth rate. * @param initSize * the initial size of this Plant, in ounces * @param initRate * the initial growth rate of this Plant, in ounces * Precondition: * initSize >= 0. Also, if initSize is zero, then * initRate must also be zero. * Postcondition: * This Plant has been initialized. The value returned from * getSize() is now initSize, and the value * returned from getRate() is now initRate. * @exception IllegalArgumentException * Indicates that initSize or initRate violates * the precondition. **/ public Plant(double initSize, double initRate) { super(initSize, initRate); } /** * Have this Plant lose some of its size by being eaten. * @param amount * The amount of this Plant that is eaten (in ounces). * Precondition: * 0 <= amount <= getSize(). * Postcondition: * The size of this Plant has been decreased by * amount. If this reduces the size to zero, then * expire is activated. **/ public void nibbledOn(double amount) { if (amount < 0) throw new IllegalArgumentException("amount is negative"); if (amount > getSize( )) throw new IllegalArgumentException("amount is more than size"); alterSize(-amount); } }