String [] xy = new String[2];
Scanner scan = new Scanner(name);
for (int i = 0; i < 2; i++) {
xy[i] = scan.next();
}
rows = Integer.parseInt(xy[0]);
columns = Integer.parseInt(xy[1]);
double [][] tempArray = new double[rows][columns];
while(scan.hasNext()) {
scan.next(scan.nextLine());
}
for(int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
tempArray[i][j] = Double.parseDouble(scan.next());
}
}
super(tempArray);
}
protected double[][] array;
protected int rows;
protected int columns;
//Creates an empty matrix.
public Matrix(int row, int column) {
double[][] matrix = new double[row][column];
this.array = matrix;
this.rows = row;
this.columns = column;
}
//Creates a matrix using an array.
public Matrix(double[][] matrix) {
double [][] tempArray = new double[matrix.length][matrix[0].length];
for(int i = 0; i < matrix.length; i++) {
for(int j = 0; j < matrix[i].length; j++) {
tempArray[i][j] = matrix[i][j];
}
}
this.rows = matrix.length;
this.columns = matrix[0].length;
this.array = tempArray;
}
Umm.. so basically for an assignment I have in school I have to read and write an array from a file. I have certain requirements that I must follow. The first bit of code is under a child class "FileMatrix" and the second bit is the parent class "Matrix". I'm not fully sure if what i wrote even works. It is supposed to do as follows: read the first two digits from the file, set those as the rows and column length, then read the rest of the file and insert those values into the new found array. I can't even test this though because my "super (tempArray);" doesn't work. It says "Constructor call must be the first statement in the constructor."
If anyone could help me that would be great, im just really lost haha
Thanks!