/* Please note that the lack of comments in files like this is due to the fact that the program was written during class */ public class sep14 { public static void main(String[] args) { oint x, y, a, b, c; x = new oint(3); y = new oint(4); a = x.add(y); // System.out.println(a); // Obj. oriented style // a = oint.plus(x,y); // Functional style b = a.add(new oint(5)); a.changeme(b.val); // System.out.println(a.toString() + " " + b.toString()); // ----------------------------------------- matrix M1, M2; M1 = new matrix(3,4); M2 = new matrix(4,4); M1.randomize(); M2.randomize(); M1.printmatrix(); M2.printmatrix(); } // end main } // end class sep 14 class oint { public int val; public oint(int initval) { val = initval; } public String toString() { return ("" + val); } public oint add(oint y) { oint z = new oint(val + y.val); return z; } public static oint plus(oint a, oint b) { return new oint(a.val + b.val); } public oint mult(oint y) { return new oint(val * y.val); } public boolean equal(oint y) { return (val == y.val); } public boolean lessthan(oint y) { return (val <= y.val); } public void changeme(int newval) { val = newval; } } // end class oint class matrix { int[][] M; public matrix(int rows, int cols) { M = new int[rows][cols]; } public void randomize() { int i, j; // these next two commands determines the dimensions of the matrix: // M is a one-dimensional array whose elements are also arrays // so its length will be the number of rows. M[0], M[1], etc, are // themselves one-dimensional arrays, so taking the length of any of // them will determine the number of columns. int rows = M.length; int cols = M[0].length; for(i=0;i