1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Juli2301 [7.4K]
3 years ago
12

Which of the following is correct implementation code for the compareTo method in the ExpertPlayer class?

Computers and Technology
1 answer:
pochemuha3 years ago
8 0

Complete Question:

The complete question is shown in uploaded image one and two.

Answer:

Answer is E

Explanation:

In order to gain understanding of this answer let look at  each code line by line

Considering Method one :

public int compareTo(Object obj)

{

This is the deceleration of the method.

ExpertPlayer rhs = (ExpertPlayer) obj;

On this line of code above an object (obj) that is passed into the method ( compareTo)is converted to type ExpertPlayer and is being assigned to a variable(rhs) of type ExpertPlayer

if(myRating ==  rhs.myRating) return 0;

else if(myRating < rhs.myRating) return 1;

else return 1;

}

This if conditional statement above will comparing the private variable myRating defined on ExpertPlayer with the private variable on the instance of the ExpertPlayer(i.e rhs.myRating)

some might ask why is compareTo method  accessing myRating which is private variable without getters or setters method. This is because the method (compareTo )and the variable(myRating) are defined in the  same class.

Looking at  this conditional statement we see that

if myRating == rhs.Rating it will return 0

if myRating < rhs.Rating it will return -1 a negative value

if myRating > rhs.Rating it will return 1 a positive value

Considering Method two

public int compareTo(Object obj)

{

As usual this code above is the deceleration of the method.

ExpertPLayer rhs = (ExpertPlayer) obj;

On this line of code above an object (obj) that is passed into the method ( compareTo)is converted to type ExpertPlayer and is being assigned to a variable(rhs) of type ExpertPlayer

return myRating – rhs.myRating;

}

On this line of code above a variable of an instance of ExpertPlayer class (i.e rhs.myRating) is subtracted from a private variable ( myrating) in ExpertPlayer class

Now looking at this code we see that if they are equal(i.e if myrating is equal to rhs.myRating) 0 will be returned

if myRating is less than rhs.myRating a negative value is returned

and if myRating is greater than rhs.myRating a positive value is return

comparing this with the first method we see that they are the same.

Considering Method Three

public int compareTo(Object obj)

{

As usual this code above is the deceleration of the method.

ExpertPLayer rhs = (ExpertPlayer) obj;

On this line of code above an object (obj) that is passed into the method ( compareTo)is converted to type ExpertPlayer and is being assigned to a variable(rhs) of type ExpertPlayer

if (getName().equals(rhs.getName()))

       return 0;

   else if (getName().compareTo(rhs.getName()) < 0)

       return -1;

   else

       return 1;

}

On the above snippet of code  myName a private variable gotten using getName() method from the HumanPlayer class which extended by ExpertPlayer class is compared with the myName variable of the instance of ExpertPlayer (i.e rhs) gotten using rhs.getName()

looking at this code above we see that it produces the same result as method one and two in that if the two compared items are the same it will return 0, if  getName() is less than rhs.getName() it will return -1 ,which is a negative value, and

if getName() is greater than rhs.getName() it will return 1 which is a positive value.

You might be interested in
ANSWER QUICKLY!
patriot [66]

Answer:

It is bit { measurement used to quantify computer data. }

7 0
3 years ago
Communication among office computers is based on a protocol that uses CRC-32 for error detection. A series of 100 identical test
Fiesta28 [93]
I think it is the CRC-32 for error detection
4 0
3 years ago
How do you represent a 3D object with unusual curves in 2D space? CAN SOMEONE HELP PLEASE
levacccp [35]
You have to draw the extra lines out
7 0
3 years ago
Create a function named CountVowels() that takes one parameter name epsilon
LenaWriter [7]

def CountVowels(epsilon):

   countNum = 0

   for x in range(len(epsilon)):

       letter = epsilon[x]

       if letter.lower() in "aeiou":

           countNum += 1

   return countNum

def ExtractOdds(zeta):

   result = ""

   for x in range(len(zeta)):

       if x % 2 == 1:

           result += zeta[x]

   return result

sentence_A = input("Enter a sentence: ")

sentence_B = input("Enter a sentence: ")

print(CountVowels(sentence_A))

print(ExtractOdds(sentence_B))

I hope this helps!

5 0
3 years ago
Explain the first to four generations of a computer​?
goblinko [34]

Answer:

<u>First generation are</u>

a)they are unreliable

b)they are very costly and

c)huge in size

<u>Second generation are</u>

a)they use a transistor

b)smaller in size compared to first generation

c)they are faster than the first generation

<u>Third generation are </u>

a)its more reliable than the first generation and the second generation

b)faster than first generation and the second generation

c)consume less electricity

<u>Fourth generation are</u>

a) they are very cheap

b)they are very small in size

c)they are portable and reliable

Explanation:

explanation is in the answer

3 0
3 years ago
Other questions:
  • A laptop gets replaced if there's a hardware issue. Which stage of the hardware lifecycle does this scenario belong to?
    5·1 answer
  • Olivia wants to add buttons and clickable features to her website. Which language should she use?
    10·2 answers
  • When creating a scene in Blender, you should change Blender Render to ______ to create the best lighting option?
    15·1 answer
  • Use fuel with the _____________ rating recommended by your vehicle manufacturer. A ) Converter B) Emission C) Exhaust D) Octane
    9·2 answers
  • What is the name of the process that weighs the alternatives, gathers all necessary information, and can ultimately lead you to
    9·2 answers
  • Which of the following is NOT a valid name for a function?
    5·1 answer
  • Biểu diễn cây sau bằng mảng một chiều
    12·1 answer
  • Draw a flow chart to access the marks of three students. calculate the total avarage and display the result​
    11·1 answer
  • True and False(Total points: 10)
    12·2 answers
  • A _____ software system determines the steps needed to produce components and instructs the machines that do the work.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!