Here is my first shot at the interface:
And here is my attempt to implement the interface with a MatrixEntity
Using interfaces are totally new to me, so I am not quite sure the best way to set one up. Also I am struggling to figure out how to then populate a MatrixEntity object with information that the user puts in from the consul, i.e. the best way to plug in each integer value to the multi dimensional array.
Thanks in advance for any and all help!
b fish wrote: Using interfaces are totally new to me, so I am not quite sure the best way to set one up. Also I am struggling to figure out how to then populate a MatrixEntity object with information that the user puts in from the consul, i.e. the best way to plug in each integer value to the multi dimensional array.
Welcome to the ranch Bobby. Could you please explain the use case in a bit more detail? What is it exactly that you are attempting to do here? Simply taking inputs from the user and storing, performing basic operations and storing them in a matrix is it? Or is there more to it?
~ Mansukh
The end goal is to have a program that can perform matrix operations for the user. Meaning the program should take values in from the user, populate them into the matrix, allow the user to choose which operation to perform (addition, multiplication, transpose, etc..), and then perform that operation. I think I have a good grip on the operations, but I am struggling with setting up the following beforehand:
1. Creating a appropriate interface
2. Creating a Matrix object that implements that interface
3. Determining the right way to take matrix values from the user (most likely using a scanner) and populating that data into the Matrix.
Once I figure out how to properly create the Matrix object and populate the user data, I think I can figure out how to manipulate via methods for the Matrix operations.
~ Mansukh
It would probably be better design to have a Matrix interface. You can then create all sorts of classes which implement that interface and use them all under the generic title “Matrix”.Mansukhdeep Thind wrote:Why do you need to have a separate interface at all?
There is no such thing as a 2D array.You could simply create the 2D array . . .
Beware: MatrixInterface is a bad name for the interface. Simply call it Matrix. It would require other methods, eg add() subtract() mutiply(), etc. I can’t remember much matrix arithmetic. Remember that you cannot add methods to the interface once you have implemented it, so make sure it has all the requisite methods before you let it loose on an unsuspecting world.
Campbell Ritchie wrote:
It would probably be better design to have a Matrix interface. You can then create all sorts of classes which implement that interface and use them all under the generic title “Matrix”.Mansukhdeep Thind wrote:Why do you need to have a separate interface at all?
There is no such thing as a 2D array.You could simply create the 2D array . . .
Beware: MatrixInterface is a bad name for the interface. Simply call it Matrix. It would require other methods, eg add() subtract() mutiply(), etc. I can’t remember much matrix arithmetic. Remember that you cannot add methods to the interface once you have implemented it, so make sure it has all the requisite methods before you let it loose on an unsuspecting world.
Thanks for the input. I have revamped this a bit and I am now trying to figure out how to properly create my matrixEntity objects in the main class. Here is my code so far:
My interface is below.
Here is the implementation of that interface without method definitions.
Here is the main class where I am attempting to create MatrixEntity objects with dimensions as specified by the user.
I keep getting an error telling me that I cannot call "createSingleMethod(m1,n1)" staticly becuase it is a non static method. Should I simply make the method static?
Also any comments on the general design? Thanks!
A method which returns the determinant of a matrix doesn't need another matrix as a parameter. It should just return the determinant of the matrix object on which it is called. So it should be
Likewise the add method should return the result of adding another matrix to the matrix object on which it is called, so it should be
(You have all of your Matrix parameters declared as double for some reason which I don't understand.)
As for the error message you're asking about  yes, your createSingleMatrix() method should be a static method. It shouldn't be a method of the Matrix type because it isn't the job of a Matrix to produce another Matrix. I also don't understand why you have two methods called createSingleMatrix and createSecondMatrix when they do exactly the same thing. Why not just a createMatrix(int, int) method?
Paul Clapham wrote:
As for the error message you're asking about  yes, your createSingleMatrix() method should be a static method. It shouldn't be a method of the Matrix type because it isn't the job of a Matrix to produce another Matrix. I also don't understand why you have two methods called createSingleMatrix and createSecondMatrix when they do exactly the same thing. Why not just a createMatrix(int, int) method?
ahhhh I see what you mean. I'll change my interface.
As for the method creating matrices, if I create a single method, how will I make the second matrix for the addition, subtraction and multiplication operations?
I guess I am just looking for a good way to create two different MatrixEntity objects so I can them use them my operations on them.
b fish wrote:As for the method creating matrices, if I create a single method, how will I make the second matrix for the addition, subtraction and multiplication operations?
I guess I am just looking for a good way to create two different MatrixEntity objects so I can them use them my operations on them.
You call the single method twice.
Paul Clapham wrote:
b fish wrote:As for the method creating matrices, if I create a single method, how will I make the second matrix for the addition, subtraction and multiplication operations?
I guess I am just looking for a good way to create two different MatrixEntity objects so I can them use them my operations on them.
You call the single method twice.
won't that create two matrices with the name "Matrix 1" ?
b fish wrote:
Paul Clapham wrote:
b fish wrote:As for the method creating matrices, if I create a single method, how will I make the second matrix for the addition, subtraction and multiplication operations?
I guess I am just looking for a good way to create two different MatrixEntity objects so I can them use them my operations on them.
You call the single method twice.
won't that create two matrices with the name "Matrix 1" ?
Since the method returns a matrix object, you could do this:
Then you would have matrix1 and matrix2 from the same method.
Life is full of choices. Sometimes you make the good ones, and sometimes you have to kill all the witnesses.
Too many men are afraid of being fools  Henry Ford. Foolish tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJIDEA
