/* $Id$
 */
package calc;

/** Storage for the registers of the calculator.
 * This is a singleton class.
 * @author Gary T. Leavens
 */
public class Registers {

    /** The number of registers.*/
    public final static int NUM_REGS = 10;

    /** The actual registers */
    private double[] regs = new double[NUM_REGS];
    
    /* prevent others from instantiating this type */
    private Registers() {}
    
    /** The only instance of this type. */
    private static Registers instance = null;

	/** Return the only instance of this type */
	public synchronized static Registers getInstance() {
		if (instance == null) {
			instance = new Registers();
		}
		return instance;
	}
	
    /** Return the value of the number stored in the given register.
     * @param num the number of the register
     */
    //@ requires 0 <= num && num < NUM_REGS;
    public double get(int num) {
        return regs[num];
    }

    /** Store a number in the given register.
     * @param num the number of the register
     * @param val the value to place in the register */
    //@ requires 0 <= num && num < NUM_REGS;
    public void put(int num, double val) {
        regs[num] = val;
    }

}
