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

Assignment 6

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)
max()
returns the largest element in the vector (an int);  if the vector has no elements, returns 0
The constructor creates an IntVec of 0 elements.  For elementAt and setElementAt, the elements are numbered starting at 0 (like Java arrays).  The vector should expand as necessary as elements are added;  there should be no fixed limit on the size of the vector.  These methods should throw an ArrayIndexOutOfBoundsException if the index is too large (this happens automatically with the simplest implementations, which allocate an array just big enough to hold the vector).

Be sure to include comments in your program, in particular explaining your addElement and max methods, as well as a line with your name.  The assignment will be graded primarily on correctness, but gross efficiency (keeping a variable in the stack rather than loading and storing it repeatedly) will also be a consideration.

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

Email your Jasmin file to the grader.  Include your name and "Asgn 6" 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.max());           // prints 20
System.out.println (iv.elementAt(6)); // throws ArrayIndexOutOfBoundsException