可以帮忙看看这个求分数加减乘除的代码哪里错了吗
package tow;
import java.util.Scanner;
public class Main {
public static void main(String args[ ]) {
Scanner reader=new Scanner(System.in);
int a,b,c,d;
a=reader.nextInt();b=reader.nextInt();
c=reader.nextInt();d=reader.nextInt();
Fraction f1=new Fraction(a,b);
Fraction f2=new Fraction(c,d);
Fraction f3=f1.add(f2);
f3.print();
Fraction f4=f1.sub(f2);
f4.print();
Fraction f5=f1.multi(f2);
f5.print();
Fraction f6=f1.divide(f2);
f6.print();
//此处补充程序
}
}
class Fraction{
int numerator;
int denominator;
Fraction(){}
Fraction(int n,int d){
numerator=n; denominator=d;
}
Fraction add(Fraction f2){
Fraction f3=new Fraction();
f3.numerator=numerator*f2.denominator+denominator*f2.numerator;
f3.denominator=denominator*f2.denominator;
return f3;
}
Fraction sub(Fraction f2){ //分数的减法运算
Fraction f4=new Fraction();
f4.numerator=numerator*f2.denominator-denominator*f2.numerator;
f4.denominator=denominator*f2.denominator;
return f4;
}
Fraction multi(Fraction f2){ //分数的乘法运算
Fraction f5=new Fraction();
f5.numerator=numerator*f2.numerator;
f5.denominator=denominator*f2.denominator;
return f5;
}
Fraction divide(Fraction f2){ //分数的除法运算
Fraction f6=new Fraction();
f6.numerator=numerator*f2.denominator;
f6.denominator=denominator*f2.numerator;
return f6;
}
void print(){
reduction();
//以下输出需要修改成符合题目要求的形式
if(numerator==0)System.out.println("0");
else if(denominator==1)System.out.println(numerator+"");
else
System.out.printf("%d/%d\n",numerator,denominator);
}
void reduction(){ //对分数进行约分,化成最简分数
//请补充完整。此处直接对numerator和denominator进行约分
//求分子分母的最大公约数,记为a
int a,x,y;
x=numerator;y=denominator;
if(x<0) x=-x;
if(y<0)
{
y=-y;denominator=-denominator;numerator=-numerator;
a=x%y;
while(a!=0)
{
x=y;y=a;a=x%y;
}
numerator=numerator/y;
denominator=denominator/y;
}
}