public class Fraction
{
private int Numer,Denom;
public Fraction ()
{
}
public Fraction (int Numer, int Denom)
{
this.Numer = Numer;
this.Denom = Denom;
}
public void setNumber(int Numer, int Denom)
{
this.Numer = Numer;
this.Denom = Denom;
}
public String toString()
{
return (Numer + " /" + Denom);
}
public static void add(Fraction c1,Fraction c2)
{
Fraction number = new Fraction();
number.Numer= (c1.Numer*c2.Denom) + (c2.Numer*c1.Denom);
number.Denom = c1.Denom * c2.Denom;
return number;
}
public void writeOutput()
{
System.out.println(Numer + " / " + Denom);
}
}
沒有留言:
張貼留言