Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote