Results 1 to 2 of 2
  1. #1
    javanator is offline Member
    Join Date
    Mar 2010
    Posts
    5
    Rep Power
    0

    Exclamation Calling methods into another class? Help please!

    So basically I have two classes:

    I have MatrixTester:

    Java Code:
    import java.util.*; 
    import java.io.*;
    
    public class MatrixTester {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		
    		int a[][] = {{1,2,-2,0},
    					{-3, 4, 7, 2},
    					{6, 0, 3, 1}}; 
    		
    		int b[][] = {{-1, 3},
    					{0, 9},
    					{1, -11},
    					{4, -5}}; 
    		
    					 
    		}
    
    	}
    And MatrixMultiply:

    Java Code:
    public class MatrixMultiply {
    		
    		public static int mult(int[][]a1, int[][]b1){
    			
    			for(int rowA=0; rowA<a1.length; rowA++){
    				
    				for(int colB=0; colB<b1.length; colB++){
    				
    					[row][col] = (row*col); 
    			
    		}
    
    		}
    		
    		
    
    	}
    
    }
    For the Tester class the instructions state that:

    1. Call a static method mult in which we pass the a and b arrays as arguments and receive back an integer array as the product matrix
    2. Print the the matrix, the output should read:

    -3 43
    18 -60
    1 -20


    After that, in the MatrixMultiply class I'm supposed to use the following instructions to write the code:

    1. No constructor
    2.The code in the mult method is to determine the dimensions of the matrices that it receives and set up a "product" array/matrix that is to be returned with appropriate dimensions
    3. The code in mult should be general so as to adapt to any two matrices to be multiplied.

    Help please!
    Last edited by javanator; 03-20-2010 at 06:30 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I'm guessing that MatrixMultiply is your code and that MatrixTester was supplied to you by your instructor, and that you are trying to fix MatrixMultiply so that it will first compile and then give a correct result. Is this correct? And if so, would it have been a good idea to give us this information in your first post? Sorry to lecture, but the quality of the help you may receive here will depend on the quality of information that you can give us.

    Some problems pop out at me:
    1) Your mult method returns an int. It's taking in two int[][] "matrices" as parameters and appears to be wanting to create its own int[][] "matrix". What do your instructions state should be returned?

    2) You'll need to declare an results int[][] with the proper row and column lengths before the for loops.

    3) You'll likely need 3 nested for loops, with the inner-most loop multiplying the matrix elements with another and summing them up to create an element of the new product matrix.

    4) Do you know how to do matrix multiplication (dot product) in general? If not, please go to the Wikipedia article on this first, because if you don't understand this yet, nothing we tell you will make much sense.

    Much luck!

Similar Threads

  1. Calling for methods
    By soccer_kid_6 in forum New To Java
    Replies: 3
    Last Post: 02-27-2010, 09:12 PM
  2. 'Class' Object and calling Static Methods?
    By mikeiz404 in forum Advanced Java
    Replies: 3
    Last Post: 01-24-2009, 12:58 PM
  3. 'Class' Object and calling Static Methods?
    By mikeiz404 in forum New To Java
    Replies: 2
    Last Post: 01-24-2009, 05:10 AM
  4. Calling Methods
    By bluegreen7hi in forum New To Java
    Replies: 3
    Last Post: 12-17-2007, 06:22 AM
  5. need help calling methods
    By lowpro in forum New To Java
    Replies: 2
    Last Post: 11-15-2007, 09:53 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •