package rebelsky.pal; /** * The PAL instruction to read an integer. * * @author Samuel A. Rebelsky * @version 1.1 of December 2002. */ public class IRead implements Instruction { // +--------+------------------------------------------------------------ // | Fields | // +--------+ /** The container to read. */ Variable location; // +--------------+------------------------------------------------------ // | Constructors | // +--------------+ /** * Create a new instruction to read a location. */ public IRead(Variable location) { this.location = location; } // IRead(Variable) // +---------+----------------------------------------------------------- // | Methods | // +---------+ /** * Execute the instruction on a machine. * * @exception Exception * If the memory location is invalid. */ public void execute(Computer hal) throws Exception { // hal.out.print("Enter an integer: "); // hal.out.flush(); location.iset(hal, Integer.parseInt(hal.in.readLine())); } // execute(Computer) /** Convert the instruction to a string (usually for printing). */ public String toString() { return " IREAD " + location.toString(); } // toString() } // class IRead