分数运算的程序
请人帮忙改下下面的程序,谢谢啦
class Rational
{
private int a;
private int b;
public Rational(int a,int b)
{
this.a = a;
this.b = b;
}
public Rational(int c)
{
this.c = c;
}
public int geta()
{
return geta;
}
public void geta(int a)
{
this.a = geta;
}
public int getb()
{
return getb;
}
public void getb(int b)
{
this.b = getb;
}
public Fraction add(Fraction summand)
{
if (this.b % summand.getb() == 0)
{
summand.seta(summand.geta() * (this.b / summand.getb()));
summand.setb(this.b);
}
else if (summand.getb() % this.b == 0)
{
this.seta(summand.a * (summand.getb() / this.b));
this.setb(summand.b);
}
else
{
int tmp = this.b;
this.setb(this.b * summand.getb());
this.seta(this.a * summand.getb());
summand.setb(tmp * summand.getb());
summand.seta(tmp * summand.geta());
}
return new Fraction(this.a + summand.geta(), this.b);
public int display()
{
if (this.a % this.b == 0)
{
return "" + this.a / this.b;
}
else if (this.b % this.a == 0)
{
return 1 + "/" + this.b / this.a;
}
else
{
return this.a + "/" + this.b;
}
}
}
class shishu
{
public static void main(String[] args)
{
Fraction a = new Fraction(1, 1);
Fraction b = new Fraction(1, 2);
System.out.println(a.add(b));
}
}
------解决方案--------------------public class Rational {
private int a;
private int b;
private int c;