In my program is supposed to throw an exception when the denominator is zero or
ID: 3543550 • Letter: I
Question
In my program is supposed to throw an exception when the denominator is zero or negative
In negative value it has to throw anexception but the program has to still running because is going to be multiply by -1
my profesor uses an testDriver so it has to throw the ilegal argument when is negative and then proccesss to multiply by one
my xcode:
if(den < 0) //Denominator cannot be negative
{
den = den * -1;
num = num * -1;
}
if(num == 0)
{
den = 1;
}
if(den <= 0) //Throws exception if denominator is zero
{
throw new IllegalArgumentException();
}
Explanation / Answer
if(den <= 0) //Throws exception if denominator is zero
{
throw new IllegalArgumentException();
}
if(den < 0) //Denominator cannot be negative
{
den = den * -1;
num = num * -1;
}
if(num == 0)
{
den = 1;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.