public class Fraction { double denominator; double numerator; /* Fraction(){ denominator=0; numerator=0; } */ Fraction(double n, double d) { denominator=d; numerator=n; change(); simplify(); } void change(){ //Fraction change(){ //Fraction tmpF= new Fraction(); String d = Double.toString(this.denominator); String n = Double.toString(this.numerator); int langD = d.length(); int langN= n.length(); int ind1 = d.indexOf('.'); int ind2 = n.indexOf('.'); int index1 = langD - ind1 - 1; int index2 = langN - ind2 -1; this.denominator = this.denominator * Math.pow(10,index1); this.numerator = this.numerator * Math.pow(10,index2); //return tmpF; } void simplify(){ //Fraction tmpF = new Fraction(); double gcd; double abs_n, abs_d; abs_n = Math.abs(this.numerator); abs_d = Math.abs(this.denominator); if(abs_d < abs_n) gcd = abs_n; else gcd = abs_d; if(abs_n == abs_d) { this.numerator /=this.denominator; this.denominator/=this.denominator; } do{ if(gcd <=1) return; //tmpF; gcd--; } while((this.denominator % gcd != 0)||(this.numerator % gcd != 0)); this.denominator /= gcd; this.numerator /= gcd; //return tmpF; } }