Matrix Program

Multiple methods, etc.

Page 1 of 1

3 Replies - 3270 Views - Last Post: 18 November 2009 - 08:18 PM Rate Topic: -----

#1 mottor   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-November 09

Matrix Program

Post icon  Posted 18 November 2009 - 06:39 PM

I have an assignment to create a program using multiple methods and multiple classes to get the determinant, inverse, product and sum.

"This class will consist of four instance variables, all of type double, called
topLeft, topRight,bottomLeft, and bottomRight. This class will also consist of
the following methods:
/*
* constructs a 2x2 matrix whose top-left, top-right,
* bottom-left and bottom-right entries are 0.0, 0.0, 0.0
* and 0.0, respectively.
*/
public Mat2By2()
/*
* constructs a 2x2 matrix
* @param topLeftVal the value of the top-left entry.
* @param topRightVal the value of the top-right entry
* @param bottomLeftVal the value of the bottom-left entry
* @param bottomRightVal the value of the bottom-right entry
*/
public Mat2By2(double topLeftVal, double topRightVal,
double bottomLeftVal, double bottomRightVal)...."
That is the first few lines of the project, and I am already lost. I don't know what the instructor expects us to use as I don't really understand Java very well.
Here is what I have so far...

package mat2by2;

public class Mat2By2
{

	public static void main(String[] args)
	{
		double topLeftVal = 0.0;
		double topRightVal = 0.0;
		double bottomLeftVal = 0.0;
		double bottomRightVal = 0.0;
	}
	public Mat2By2()
	{
	}
	public Mat2By2(double topLeftVal, double topRightVal, double bottomLeftVal, double bottomRightVal)
	{
	}


}






Is This A Good Question/Topic? 0
  • +

Replies To: Matrix Program

#2 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8379
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Matrix Program

Posted 18 November 2009 - 07:52 PM

Ok first, your class must have instance variables to hold the values
Your main() is just to test your class... it is usually posted at the end of the class

public class Mat2By2
{
	// instance variables of Mat2By2 objects
		double topLeftVal;
		double topRightVal;
		double bottomLeftVal;
		double bottomRightVal;

	// constructor to build a new Mat2By2 object
	public Mat2By2(double topLeftVal, double topRightVal, double bottomLeftVal, double bottomRightVal)
	{
		this.topLeftVal = topLeftVal;	// store value received as parameter into instance variable
		this.topRightVal = topRightVal;
		this.bottomLeftVal = bottomLeftVal;
		this.bottomRightVal = bottomRightVal;
	}
 
	// this is to unit test your class
	public static void main(String[] args)
	{
		// create a Mat2By2 object
		Mat2By2 mt = new Mat2By2(0.0, 0.0, 0.0, 0.0);
		// now that you have an instance of Mat2By2 object you can applied to it 
		// the methods you haven;t wroite yet
		mt.methodX();
	}


}




Hope this helps

*Edited to balance [ i][ /i]

This post has been edited by pbl: 18 November 2009 - 08:44 PM

Was This Post Helpful? 1
  • +
  • -

#3 mottor   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-November 09

Re: Matrix Program

Posted 18 November 2009 - 08:09 PM

That helps a lot. So now I apparently have the potential to store one matrix. I need to be able to use two matrices so that I can add them, subtract them, etc. Can you point me in the right direction? This is what I'm up to at this point.












package mat2by2;

import java.util.Scanner;

public class Mat2By2
{
	// instance variables
	double topLeftVal;
	double topRightVal;
	double bottomLeftVal;
	double bottomRightVal;
	
	// constructor to build a new object
	public Mat2By2(double topLeftVal, double topRightVal, double bottomLeftVal, double bottomRightVal)
	{
	this.topLeftVal = topLeftVal;
	this.topRightVal = topRightVal;
	this.bottomLeftVal = bottomLeftVal;
	this.bottomRightVal = bottomRightVal;
	}
	
	// determines the determinant of a matrix
	public double determinant()
	{
		double determinant = (topLeftVal * bottomRightVal) - (topRightVal * bottomLeftVal);
		return determinant;
	}
	
	// needs to add corresponding values of two matrices
	public Mat2By2 add(Mat2By2 right)
	{
		double sum =;
		return sum;
	}
	public Mat2By2 subtract(Mat2By2 right)
	{
		
	}
	public Mat2By2 multiply(Mat2By2 right)
	{
		
	}
	public Mat2By2 inverse()
	{
	   
	}
	public String toString()
	{
		string toString = new String("{{%.2d,%.2d},{%.2d,%.2d}}", topLeftVal, topRightVal, bottomLeftVal, bottomRightVal);
		return toString;
	}

}


class Client
{
	Scanner keyboard = new Scanner(System.in);
	
}



Was This Post Helpful? 0
  • +
  • -

#4 mottor   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-November 09

Re: Matrix Program

Posted 18 November 2009 - 08:18 PM

P.S.
The Client class is our test class

This post has been edited by mottor: 18 November 2009 - 08:22 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1