logo

Crowdly

Looking for test answers and solutions? Browse our comprehensive collection of verified answers for at moodle.lsu.edu.

Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!

Consider the following code snippet for recursive addition:

int add(int i, int j) 

   // assumes i >= 0

   if (i == 0)

   {

      return j;

   }

   else

   {

      return add(i - 1, j + 1);

   }

}

Identify the terminating condition in this recursive method.

0%
100%
0%
0%
View this question

Consider the getArea method from the textbook shown below.

public int getArea()

{

   if (width <= 0) { return 0; } // line #1

   else if (width == 1) { return 1; } // line #2

   else

   {

      Triangle smallerTriangle = new Triangle(width - 1); // line #3

      int smallerArea = smallerTriangle.getArea();  // line #4

      return smallerArea + width;  // line #5

   }

}

Where is/are the terminating condition(s)?

0%
0%
0%
100%
View this question

Consider the getArea method from the textbook shown below.

public int getArea()

{

   if (width <= 0) { return 0; } // line #1

   else if (width == 1) { return 1; } // line #2

   else

   {

      Triangle smallerTriangle = new Triangle(width - 1); // line #3

      int smallerArea = smallerTriangle.getArea();  // line #4

      return smallerArea + width;  // line #5

   }

}

Where is/are the recursive call(s)?

0%
100%
0%
0%
View this question

What is required to make a recursive method successful?

I  special cases that handle the simplest computations directly

II a recursive call to simplify the computation

III a mutual recursion

0%
0%
0%
100%
View this question

Consider the following code snippet:

public class Inventory implements Measurable

{

   private int onHandCount;

   . . .

   double getMeasure();

   {

      return onHandCount;

   }

}

Assume thatgetMeasure() is a method in the interface Measurable. The compiler complains that the getMeasure method has a weaker access level than the Measurable interface. Why? 

0%
100%
0%
0%
View this question

Consider the following code snippet:

public class Inventory implements Measurable

{

   private int onHandCount;

   . . .

   double getMeasure();

   {

      return onHandCount;

   }

}

If getMeasure() is a method in the interface Measurable, what is wrong with this code? 

0%
0%
100%
0%
View this question

Consider the following code snippet:

public class BankAccount implements Comparable<BankAccount>

{   . . .

   public int compareTo(T other)

   {

What is wrong with this code?

100%
0%
0%
0%
View this question

Consider the following code snippet:

public class Inventory implements Measurable

Which of the following statements about this code is correct?

0%
100%
0%
0%
View this question

You are creating a Vessel class which is supposed to use an interface named Measurable. Which of the following class declaration statements will accomplish this? 

0%
100%
0%
0%
View this question

You are creating a Motorcycle class which is supposed to use an interface named Measurable. Which of the following class declaration statements will accomplish this?

0%
100%
0%
0%
View this question

Want instant access to all verified answers on moodle.lsu.edu?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!