4 Replies - 13281 Views - Last Post: 06 December 2007 - 11:33 PM Rate Topic: -----

#1 kshiman  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 8
  • Joined: 19-September 07

MATRIX JAVA

Posted 06 December 2007 - 08:53 PM

WONT COMPILE, ERROR LINES 50 AND 54 DUE TO MISSING RETURN STATEMENT. I AM NOT QUITE SURE WHAT THAT MEANS. PLEASE HELP!!! ALSO WHEN I TRY AND RUN THE PROGRAM, IT SAYS THAT THE CLASS "MATRIX" IS UNDEFINED.


 import java.util.*;


public class Matrix {
  
  private static int [][] anArray = new int [3][3];
  static int []row = new int [3];
  static int []column = new int [3];
  

public static void clear(Matrix a){
  
  
  
}
public static void swap (Matrix a, Matrix b){
int[] temp = anArray[3];
anArray[3] = anArray[3];
anArray[3] = temp;
}
public static void fill(Matrix a){
  int value;
  Scanner scan = new Scanner(System.in);
  System.out.println("Please enter the value you will to fill each row with, one row at a time. ");
  value = scan.nextInt();
  
  
}
public static void print(Matrix a){
  
  
}
public static Matrix addition(Matrix a, Matrix b){
  Matrix c = new Matrix();
  for (int i = 0; i < row.length; i++)
	for (int j = 0; j < column.length; j++)
	c.anArray[i][j] = a.anArray[i][j] + b.anArray[i][j];
  return c;
  
}  
public static Matrix multiply(Matrix a, Matrix b){

  
}  
public Matrix transpose(){
  
  
}

}


Is This A Good Question/Topic? 2
  • +

Replies To: MATRIX JAVA

#2 dontKnowJava  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 221
  • Joined: 29-September 07

Re: MATRIX JAVA

Posted 06 December 2007 - 08:59 PM

means public static Matrix multiply(Matrix a, Matrix B) and public Matrix transpose() are supposed to return a Matrix but since they are blank and dont have a return statement you get an error
Was This Post Helpful? 0
  • +
  • -

#3 kshiman  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 8
  • Joined: 19-September 07

Re: MATRIX JAVA

Posted 06 December 2007 - 09:05 PM

Can you help me? I am not sure what you mean they are empty. my program should add two nxn matrices. and give an output which would be matrix c.

View PostdontKnowJava, on 6 Dec, 2007 - 08:59 PM, said:

means public static Matrix multiply(Matrix a, Matrix B) and public Matrix transpose() are supposed to return a Matrix but since they are blank and dont have a return statement you get an error

Was This Post Helpful? 0
  • +
  • -

#4 kshiman  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 8
  • Joined: 19-September 07

Re: MATRIX JAVA

Posted 06 December 2007 - 09:19 PM

Does anyone know what return statement I need to input for it to return an output of Matrix a added with Matrix b ???
Was This Post Helpful? 0
  • +
  • -

#5 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4421
  • View blog
  • Posts: 12,286
  • Joined: 18-April 07

Re: MATRIX JAVA

Posted 06 December 2007 - 11:33 PM

You have a lot of issues with this code. dontknowJava is exactly right about the return statement issue. You have two functions there that are suppose to return instances of class Matrix and they don't. Hence the return errors. But another bigger problem he failed to mention was how you named your main project class Matrix and then using Matrix class variables in all your parameters. They can't be the same. What you are saying is that I want to create a main class called Matrix and then pass itself to its own methods which makes no sense.

On top of all this you are passing matrix parameters to functions like "swap" but then never ever using them.

You are suppose to create a matrix class outside of the main program and name them two different things. For instance, call your main program "MyMatrixProject" and then create a separate class called "Matrix" which would then make some of this code work. This is what the error "Matrix is Undefined" is telling you. It knows that the project is called Matrix, but it doesn't know what a Matrix class is.

You are right in defining the multidimensional array inside the class, but again that class is suppose to be separate from the program. It doesn't have to be a separate file, but it has to be a separate implementation from the main program. Then you will need to create instance variables of type matrix.

I hope this is making some sense. Once you write your matrix class, you will start seeing your parameters for some of these functions will disappear. Like the print function. If implemented in a separate Matrix class definition, it would be just "print()" with no parameters. It would then print the private data member anArray.

Take this advice and rework it into a different form and see what you get. :)
Was This Post Helpful? 1

Page 1 of 1