rationalmatrix.java
来自「此源码为机械工业出版社出版的《Java语言程序设计》第三版所配套的书中所有源代码」· Java 代码 · 共 40 行
JAVA
40 行
// RationalMatrix.java:
// Declare RationalMatrix derived from GenericMatrix
public class RationalMatrix extends GenericMatrix
{
// Construct a RationalMatrix for a given Ratonal array
public RationalMatrix(Rational[][] m1)
{
super(m1);
}
// Implement the createGenericMatrix method
public GenericMatrix createGenericMatrix()
{
Rational[][] matrix = new Rational[getMatrix().length][getMatrix().length];
return new RationalMatrix(matrix);
}
// Implement the add method for adding two rational elements
protected Object add(Object o1, Object o2)
{
Rational r1 = (Rational)o1;
Rational r2 = (Rational)o2;
return r1.add(r2);
}
// Implement the multiply method for multiplying
// two rational elements
protected Object multiply(Object o1, Object o2)
{
Rational r1 = (Rational)o1;
Rational r2 = (Rational)o2;
return r1.multiply(r2);
}
// Implement the zero method to specify zero for Rational
protected Object zero()
{
return new Rational(0,1);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?