Search code examples
javasparse-matrix

Implementation of Sparse Matrix based on standard Stack generates compile errors


I am implementing a sparse matrix based on the Stack class, and I'm getting the following error:

Sparse.java:6: Sparse is not abstract and does not override abstract method pop() in Stack
public class Sparse implements Stack {

Here is the code snippet in question:

public class Sparse implements Stack {

    static int matrix[][] = new int[6][6];

    public static int[][] Random() {
        Random rand = new Random(seed);
        rand.nextInt(100);
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < array[0].length; j++) {
                matrix[i][j] = rand.nextInt(100);
            }
            return matrix;
        }
    }
}

Any and all help would be appreciated. Thank you.


Solution

  • It means the interface Stack has a method pop(). You must implement the method pop() or it won't compile.

    If you must test your code quick and implement the method later, you may want to

    public int pop() { // Refer to your Stack interface for signature - they must match.
        throw new UnsupportedOperationException("not implemented");
    }