V22.0201 (sec. 1) - Computer Systems Organization (Honors)

Assignment 4

Write, in Jasmin, a JVM class IntVec for vectors of ints.  The class definition must include a constructor (with no arguments) and the following methods:
 
addElement(int e)
adds element e to end of vector;  returns void
elementAt(int i)
returns i-th element of vector (an int)
setElementAt(int e, int i)
sets i-th element of vector to e;  returns void
size()
returns number of elements in vector (an int)
The constructor creates an IntVec of 0 elements.  For elementAt and setElementAt, the elements are numbered starting at 0 (like Java arrays).  These methods should throw an ArrayOutOfBoundsException if the index is too large.

Be sure to include comments in your program, and in particular include a line with your name.

This assignment is due on November 20th.  There is a penalty of 1/2 point (out of a total of 7 points) for each day late.

Email your Jasmin file to the grader.  Include your name and "Asgn 4" in the subject line.


Example of using IntVec:

IntVec iv = new IntVec();
System.out.println (iv.size());          // prints 0
iv.addElement(5);
iv.addElement(10);
System.out.println (iv.size());          // prints 2
System.out.println (iv.elementAt(1));    // prints 10
iv.setElementAt(20,1);
System.out.println (iv.elementAt(1));    // prints 20
System.out.println (iv.elementAt(6)); // throws ArrayOutOfBoundsException