// ITU F2005 JMA - Mandatory assignment #1 // intArray.java // 2005-03-01 Kenn A. Thisted import javax.microedition.midlet.*; import java.io.*; import javax.microedition.io.*; import java.util.Vector; import java.util.Enumeration; public class intArray extends Vector { private MIDlet midlet; private Plot plot; // URL: http://www.itu.dk/courses/JMA/F2005/small.txt // URL: http://www.itu.dk/courses/JMA/F2005/large.txt public intArray() { super(); InputStream is = null; try { is = getClass().getResourceAsStream("small.txt"); //is = getClass().getResourceAsStream("large.txt"); int ch; int x = 0; while( ( ch = is.read() ) != -1 ) { //System.out.print( (char) ch ); switch (ch) { case '\r': is.read(); case '\n': this.addElement(new Integer(x)); x = 0; break; default: x = 10 * x + (ch - '0'); } } } catch( IOException e ) { System.out.println( e.toString() ); } finally { //is.close(); //will not compile? } } public int[] toArray() { int i = 0; int[] y; for(Enumeration e = this.elements() ; e.hasMoreElements() ;) { e.nextElement(); i++; } y = new int[i]; i = 0; for(Enumeration e = this.elements() ; e.hasMoreElements() ;) { y[i] = ((Integer)e.nextElement()).intValue(); i++; } return y; // int array of y values } } /* Just a template - has to be modified InputStream is = getClass().getResourceAsStream(“small.txt"); try{ int ch; while ((ch=is.read()) !=-1) { switch (ch) { case '\r': is.read(); case '\n': v.addElement(new Integer(x)); x = 0; break; default: x = 10 * x + (ch - '0'); } } */