Need help with fixing an error dealing with interface implementation

Hi everyone, I wrote the following code for a Fraction class that implements an interface called StdMathOps which consists of 5 methods called add, sub, div mult, and toString. I am getting a compilation error which says "Fraction is not abstract and does not override abstract method mult(Object) in StdMathOps." I do not intend for Fraction to be an abstract class as it does implement each of the 5 methods in the interface, and am wondering if anyone can help me in identifying what needs to be corrected. Any help would be greatly appreciated.

Here is the interface:

Here is the Fraction class:

Code java:

public class Fraction implements StdMathOps
{
private int num;
private int den;
public Fraction(int a, int b)
{
num = a;
den = b;
}
public Fraction()
{
num = 1;
den = 1;
}
@Override
public String toString()
{
return num + "/" + den;
}
public double getDecimal()
{
double decimal = ((double)num / den);
return decimal;
}
public String reduce()
{
int n = num;
int d = den;
while(n != d)
{
if(n > d)
n = n - d;
if(d > n)
d = d - n;
}
return((num / d) + "/" + (den / d));
}
public String toMixed()
{
int a = num;
int b = den;
int whole = num / den;
while(a != b)
{
if(a > b)
a = a - b;
if(b > a)
b = b - a;
}
Fraction g = new Fraction(num % den / b, den / b);
if(whole > 0)
return whole + " " + g.toString();
else
return g.toString();
}
public Fraction add(Fraction a)
{
int newNum = (((a.den * den) / a.den) * a.num) + (((den * a.den) / den) * num);
int newDen = (a.den * den );
Fraction x = new Fraction(newNum, newDen);
return x;
}
public Fraction sub(Fraction a)
{
int newNum = ((num * a.den) - (a.num * den));
int newDen = den * a.den;
Fraction x = new Fraction (newNum, newDen);
return x;
}
public Fraction div(Fraction a)
{
int newNum = num * a.den;
int newDen = den * a.num;
Fraction x = new Fraction (newNum, newDen);
return x;
}
public Fraction mult(Fraction a)
{
int newNum = num * a.num;
int newDen = den * a.den;
Fraction x = new Fraction (newNum, newDen);
return x;
}
}

Re: Need help with fixing an error dealing with interface implementation

Hi jc,

You need to actually have the function definition match that of the interface. So you should change from Fraction in the parameters and return to Object.

Or, perhaps a smarter solution would be to use generics in the StdMathOps interface, such as the following. ( I'll let you work out the last part of the puzzle.... )

Code java:

public interface StdMathOps<T>
{
public T add(T o);
public T sub(T o);
public T div(T o);
public T mult(T o);
@Override
public String toString();
}

If you would like more information about generics, then check this out: http://docs.oracle.com/javase/tutorial/java/generics/

Re: Need help with fixing an error dealing with interface implementation

Got it, thank you for your assistance.