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

2. Consider the method isMaleTeenager as implemented below. Rewrite the method w

ID: 3756492 • Letter: 2

Question

2. Consider the method isMaleTeenager as implemented below. Rewrite the method with 3 error-producing mutations, each of which propagates the error to the method return value

For each of the 3 mutations, write a test case (in terms of the 2 method parameters and the method return value) which kills the mutant

/**

*isMaleTeenager – does the gender/ age combination indicate a male teenager?

* *@Param male true if male; false otherwise

*@Param age age if years

*@return true if male and age is between 13 and 19 Inclusive; false otherwise

*/

Public Boolean isMaleTeenager(Boolean male, int age)

{ Boolean maleTeenager = false;

If (male)

{

If (age >= 13 && age <= 19)

{

maleTeenager = true ;

}

}

Return maleTeenager;

}

Explanation / Answer

Please find the code below in Java.

CODE

=====================

/**

   * isMaleTeenager – does the gender/ age combination indicate a male teenager?

   * @Param male true if male; false otherwise

   * @Param age age if years

   * @return true if male and age is between 13 and 19 Inclusive; false otherwise

   * @throws Exception

   */

   public static Boolean isMaleTeenager(Boolean male, int age) {

       if (!male) {

           System.out.println("Not a male!!");

           return false;

       } else {

           if(age < 13) {

               System.out.println("Age is less than 13!!");

               return false;

           } else if(age > 19) {

               System.out.println("Age is more than 19!!");

               return false;

           }

           return true;

       }

   }

  

Test Methods

**************************

   @Test

   public void testIsMaleTeenagerWhenGenderIsNotMale() {

       Boolean response = isMaleTeenager(false, 18);

       Assert.assertFalse(response);

   }

  

   @Test

   public void testIsMaleTeenagerWhenAgeIsLessThan13() {

       Boolean response = isMaleTeenager(true, 12);

       Assert.assertFalse(response);

   }

  

   @Test

   public void isMaleTeenagerWhenAgeIsMoreThan19() {

       Boolean response = isMaleTeenager(true, 18);

       Assert.assertFalse(response);

   }

  

   @Test

   public void isMaleTeenagerReturnsTrue() {

       Boolean response = isMaleTeenager(true, 20);

       Assert.assertTrue(response);

   }

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