package calc;

/** Formulas for the calculator.
 * @author Gary T. Leavens
 */
public class Formula implements FormulaType {
    /** The left register */
    private /*@ spec_public @*/ int left;
    /** The right register */
    private /*@ spec_public @*/ int right;
    
    /**
     * Initialize this Formula object to be the sum of the given registers.
     * @param left the left register's number.
     * @param right the right register's number
     */
    //@ requires 0 <= left && left < Registers.NUM_REGS;
    //@ requires 0 <= right && right < Registers.NUM_REGS;
    //@ ensures this.left == left && this.right == right;
    public Formula(int left, int right) {
        this.left = left;
        this.right=right;
    }
    
    /**
     * Evaluate the formula and return its value.
     */
    /*@ also
      @   ensures (* \result is the sum of the value of
      @              the left and right register's values. *); @*/
    public double evaluate() {
        return Registers.get(left) + Registers.get(right);
    }
}