Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 My matrix program
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Gerkin




PostPosted: Tue May 31, 2005 9:07 pm   Post subject: My matrix program

code:

import java.lang.*;

public class matrixmaker2

{
    public static void main (String args[])

    {
        int dimensioncoulmns;
        int dimensionrows;
        int mymatrix[] [];
        //int width[][];
        System.out.println ("Welcome to Matrix maker!");
        System.out.println ("------------------------");
        System.out.println ("Enter the dimensions of the matrix:");
        System.out.println ("Please first enter in the number of rows u wish to have in the matrix:");
        dimensionrows = TextIO.getInt ();
        System.out.println ("Now please enter in the length of the number of coulmns u wish to have:");
        dimensioncoulmns = TextIO.getInt ();

        System.out.println ("Dimensions are: " + dimensionrows + " rows " + "by " + dimensioncoulmns + " coulmns.");
        //height =  new int [dimensionheight];
        //width = new int [dimensionwidth];
        mymatrix = new int [dimensioncoulmns] [dimensionrows];
        for (int i = 0 ; i < dimensioncoulmns ; i++)
        {
            for (int j = 0 ; j < dimensionrows ; j++)
            {

                System.out.println ("Plz enter in the number u wish to have in position row " + (i+1) + " coulmn " + (j+1));
                mymatrix [i] [j] = TextIO.getInt ();

            }
        }
        System.out.println ("");
        System.out.println ("");
        System.out.println ("");
        System.out.println ("Here is your matrix with the dimensions of " + dimensionrows + " by " + dimensioncoulmns);
        System.out.println ("");
        System.out.println ("");
       
        for (int i = 0 ; i < dimensioncoulmns ; i++)
        {
            System.out.print ("( ");
       
            for (int j = 0 ; j < dimensionrows ; j++)
            {

                System.out.print (mymatrix [i] [j] + " ");

            }
            System.out.print (")");
           
            System.out.print ("\n");
        }
    }
}




As you can see, the program creates matrices. What I want to do is make this program able to multiply and add another matrix with GUI. What I need to know is how to open a matrix with rows and columns corresponding to the number of textboxes in the new window.
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Tue May 31, 2005 11:01 pm   Post subject: (No subject)

My suggestion is to create a Matrix class, so you can easily have multiple matrix objects.

Java:
class Matrix<T>
{
   private int rows, cols;
   private T[][] data;

   public Matrix(int cols, int rows)
   {
      this.rows = rows;
      this.cols = cols;
      // array initialization
   }

   public Matrix(int cols, int rows, T default)
   {
      this.rows = rows;
      this.cols = cols;
      // array initialization with default value
   }

   public int getRows()
   {

   }

   public int getCols()
   {
     
   }

   public T at(int row, int col)
   {
      return data[row][col];
   }

   public void setAt(int row, int col, T value)
   {
      data[row][col] = value;
   }

   public String toString()
   {

   }
}
McKenzie




PostPosted: Wed Jun 01, 2005 1:53 am   Post subject: (No subject)

With anyone else most readers would know that kava is just a typo, but because you know so many languages many readers will assume this is some sort of Java offshoot language. The only problem with your code is that because Generics were only introduced in JDK 5.0 the vast majority of the students won't be able to use this at school.
wtd




PostPosted: Wed Jun 01, 2005 2:06 am   Post subject: (No subject)

Thanks for spotting that. I guess there are times when my own level of knowledge comes back to bite me. Smile
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: