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

4. Consider the following method, between, which is intended to return true if x

ID: 3718313 • Letter: 4

Question

4. Consider the following method, between, which is intended to return true if x is between lower and upper, inclusive, and false otherwise.

//precondition: lower <= upper
//postcondition: returns true if x is between lower and upper,
//                     inclusive; otherwise, returns false
public boolean between(int x, int lower, int upper)
{
     /*missing code */
}

Which of the following can be used to replace /* missing code */ so that between will work as intended?

Question 4 options:

return (x <= lower) || (x >= upper);

return (x >= lower) || (x <= upper);

return (x <= lower) && (x >= upper);

return (x >= lower) &&(x <= upper);

return lower <= x <= upper;

5. Consider the following class declaration.

public class IntCell
{
     private int myStoredValue;

     //constructor not shown
     public int getValue()
     {
            return myStoredValue;
    }

      public String toString()
      {
              return "" + myStoredValue;
      }
}

Assume that the following declarations appears in a client class.

            IntCell m = new IntCell();
Which of these statements can be used in the client class?

I. System.out.println (m.getValue());

II. System.out.println (m.myStoredValue);

III. System.out.println (m);

Question 5 options:

III only

II only

I and II

I only

I and III

6. Consider the following method.

public void conditionalTest(int a, int b)
{
    if (( a > 0) && ( b > 0))
    {
        if (a > b)
                System.out.println ("A");
        else
                System.out.println ("B");
    }
    else if ((b < 0) || (a < 0))
          System.out.println("C");
    else
          System.out.println ("D");
}

What is printed as a result of the call conditionalTest(3, -2)?

Question 6 options:

C

B

Nothing is printed.

A

D

return (x <= lower) || (x >= upper);

return (x >= lower) || (x <= upper);

return (x <= lower) && (x >= upper);

return (x >= lower) &&(x <= upper);

return lower <= x <= upper;

Explanation / Answer

Ans:4

D) return (x >= lower) &&(x <= upper);

Ans:5

Option B is correct.

I. System.out.println (m.getValue());

Ans:6

Option A

C will be printed.

Explanation:

else if ((b < 0) || (a < 0))                      //-2 < 0 true
          System.out.println("C");

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

Kindly Check and Verify Thanks..!!!

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