The following code segment appears in a class other than Backyard. It is intended to print true if b1 and b2 have the same lengths and widths, and to print false otherwise. Assume that x, y, j, and k are properly declared and initialized variables of type int.

Backyard b1 = new Backyard(x, y);
Backyard b2 = new Backyard(j, k);
System.out.println( /* missing code */ );

Which of the following can be used as a replacement for /* missing code */ so the code segment works as intended?

a. b1 == b2
b. b1.equals(b2)
c. equals(b1, b2)
d. b1.equals(b2.getLength(), b2.getWidth())
e. b1.length == b2.length && b1.width == b2.width

Respuesta :

Answer:

b. b1.equals(b2)

Explanation:

The question has a missing source file (which can be found online).

The function that compares b1 and b2 is:

public boolean equals(Object other) {

if (other == null) {

return false; }

Backyard b = (Backyard) object;

return (length == b.getLength() && width == b.getWidth());

}

Using the function definition, we have:

equals(Object other)

This implies that, the first object will be compared to the second, using the function name.

i,e,

b1.equals(b2)

Hence (b) is correct

In this exercise we have to use the knowledge in computational language in C++ to describe a code that best suits, so we have:

The code can be found in the attached image.

To make it simpler we can write this code as:

public boolean equals(Object other) {

if (other == null) {

return false; }

Backyard b = (Backyard) object;

return (length == b.getLength() && width == b.getWidth());

}

This program will result in the following missing variable:

b1.equals(b2)

See more about C++ at brainly.com/question/19705654

Ver imagen lhmarianateixeira
ACCESS MORE