Android Open Source - simple-matrix Rational






From Project

Back to project page simple-matrix.

License

The source code is released under:

MIT License

If you think the Android project simple-matrix listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.alexkang.x3matrixcalculator.calculations;
//from  w ww .j a v  a2s. c o  m
public class Rational {
  
  int num;
  int denom;
  
  public Rational(int num) {
    this.num = num;
    this.denom = 1;
  }
  
  public Rational(int num, int denom) {
    this.num = num;
    this.denom = denom;
    this.simplify();
  }
  
  private int gcd(int num, int denom) {
    return denom == 0 ? num: gcd(denom, num % denom);
  }
  
  private void simplify() {
    int x = gcd(num, denom);
    this.num = num / x;
    this.denom = denom / x;
    if (denom < 0) {
      this.num = num * -1;
      this.denom = denom * -1;
    }
  }
  
  public int getNum() {
    return num;
  }
  
  public int getDenom() {
    return denom;
  }
  
  public void setNum(int n) {
    this.num = n;
    this.simplify();
  }
  
  public void setDenom(int n) {
    this.denom = n;
    this.simplify();
  }
  
  public String getString() {
    if (denom == 1) {
      return num + "";
    }
    return num + "/" + denom;
  }
}




Java Source Code List

com.alexkang.x3matrixcalculator.DisplayResultActivity.java
com.alexkang.x3matrixcalculator.MainActivity.java
com.alexkang.x3matrixcalculator.MatrixRational.java
com.alexkang.x3matrixcalculator.Matrix.java
com.alexkang.x3matrixcalculator.SettingsActivity.java
com.alexkang.x3matrixcalculator.calculations.Advanced.java
com.alexkang.x3matrixcalculator.calculations.Basic.java
com.alexkang.x3matrixcalculator.calculations.RationalAdvanced.java
com.alexkang.x3matrixcalculator.calculations.RationalBasic.java
com.alexkang.x3matrixcalculator.calculations.RationalCalc.java
com.alexkang.x3matrixcalculator.calculations.Rational.java