⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rationalmatrix.java

📁 此源码为机械工业出版社出版的《Java语言程序设计》第三版所配套的书中所有源代码。
💻 JAVA
字号:
// 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -