
/**
 * This class can be used to simulate the paper folding puzzle.
 * 
 * @author Dave Reed 
 * @version 9/10/09
 */
public class PaperSheet {
    private double thickness;   // thickness in inches
    private int numFolds;       // the number of folds so far

    /**
     * Constructs the PaperSheet object
     *   @param initial  the initial thickness (in inches) of the paper
     */   
    public PaperSheet(double initial) {
        this.thickness = initial;
        this.numFolds = 0;
    }
    
    /**
     * Folds the sheet, doubling its thickness as a result
     */   
    public void fold() {
        this.thickness = 2 * this.thickness;
        this.numFolds = this.numFolds + 1;
    }
    
    /**
     * Repeatedly folds the sheet until the desired thickness is reached
     *   @param goalDistance  the desired thickness (in inches) 
     */   
    public void foldUntil(double goalDistance) {
        while (this.thickness < goalDistance) {
            this.fold();
        }
    }
    
        /**
     * Accessor method for determining folds
     *   @return the number of times the paper has been folded
     */   
    public int getNumFolds() {
        return this.numFolds;
    }
}
