package lab02;

public class Memory {
	
	/**
		Under the covers, we will simulate a RAM memory using a Java
		array. Since we haven't learned about Java arrays yet, the basics
		are provided for you. I have declared a field called "data" which
		is an array of integers.
	**/
	
	int data[];
	
	public Memory(int length) {
		/**
			The memory constructor creates an actual array big enough to
			hold "length" integers.
		**/
		data = new int[length];
	}
	
	public void set(int loc,int val) {
		if (loc<0 || loc>data.length) 
			System.out.println("Error... Invalid memory address: " + loc + " during set");
		else data[loc]=val;
	}
	
	public int get(int loc) {
		if (loc<0 || loc>data.length) { 
			System.out.println("Error... Invalid memory address: " + loc + " during get");
			return -1;
		}
		else return data[loc];
	}

}
