classdef Fraction < handle
% A Fraction has a numerator (num) and a denominator (denom).
% A negative fraction has a negative numerator and a positive denominator.
% If the denominator is zero, set the numerator to +/- inf and the
% denominator to 1.
% Assume numerator and denominator are integers (except for the case of inf).

properties
num % numerator
denom % denominator
end

methods
function frac = Fraction(nu, de)
% Constructor: construct a Fraction object and return its handle
if de<0 % need to make denominator positive
nu= -nu;
de= -de;
end
if de~=0 % normal fraction
frac.num= nu;
frac.denom= de;
else % denominator is zero
if nu==0 % set fraction to NaN (Not a Number)
frac.num= NaN;
elseif nu<0 % set fraction to -Inf
frac.num= -Inf;
else % set fraction to +Inf
frac.num= Inf;
end
frac.denom= 1;
end
end

function tf = isLessThan(self, other)
% tf is true if self is strictly less than the other Fraction
tf= self.num*other.denom < other.num*self.denom;
end

function prod = multiply(self, other)
% prod is the product of self and other
prod= Fraction(self.num*other.num, self.denom*other.denom);
end

end %methods

end %classdef