public class Fraction { private int numer; private int denom; public int getNumerator() { return this.numer; } public int getDenominator() { return this.denom; } public void setNumerator(int n) { this.numer = n; } public void setDenominator(int d) { if (d != 0) { this.denom = d; } else { this.numer = 0; this.denom = 1; } } public Fraction(int num, int den) { this.setNumerator(num); this.setDenominator(den); } public void simplify() { for(int i = 2; i <= this.denom; i+=1) { if ((this.numer % i) == 0 && (this.denom % i) == 0) { this.numer /= i; this.denom /= i; } } } public Fraction add(Fraction that) { int num = this.numer * that.denom + this.denom * that.numer; int den = this.denom * that.denom; return new Fraction(num, den); } public double getValue() { return this.numer / (double)(this.denom); } public String toString() { return this.numer +"/"+ this.denom; } }