need help to add main class to test this program.
public class Rational
{
private int num;
private int den;
public Rational ( )
{
num = 0;
den = 1;
}
public Rational (int a, int B)
{
num = a;
den = b;
simplify ( );
}
private void simplify ( )
{
int GCD = getGCD (num,den);
num /= GCD;
den /= GCD;
}
private int getGCD ( int a, int b )
{
int dividend = Math.abs (a);
int divisor = Math.abs (B);
int rem = 0;
do
{
rem = dividend % divisor;
if (rem != 0)
{
dividend = divisor;
divisor = rem;
}
} while (rem != 0);
return divisor;
}
public double getValue ( )
{
return (double) num / den;
}
public String toString ( )
{
String outString = "";
if ((num * den) < 0)
outString += "-";
outString += (Math.abs (num));
if (Math.abs (den) != 1)
outString += ("/" + Math.abs (den));
return outString;
}
}