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
The management of Ventura Inc. approves the purchase of a few computers for the sales team. The management wants only the most b
BaLLatris [955]

Answer:

Ventura Inc requires only System software's

Explanation:

The system software has three major functions which are:

1. File and disk management: this involve managing of files in the system, when user want to save, move, copy, delete and rename files, The system software will handle those task

2. Allocating system resources: The system resources such as time, memory, data input and output are  allocated by the system software. The main memory is managed by the system software to avoid conflict among various task.

3. Monitoring system activities:  The system security and system performance is also monitored by the system software.

The first two functionalities are the requirement of ventura inc  

8 0
3 years ago
A screen saver is best described as a
sashaice [31]
A wallpaper or background.
3 0
3 years ago
What is A wage paid based on the ability to sell a product or service is (a) _____.
Fantom [35]
The answer is commissioned
5 0
4 years ago
I need the answers. i don’t get this
bixtya [17]
Run,lazy,turtles,slow,wandering, jump,45,weird,pigs, cows, cousins, pale,rude,candles

There are many answers for this but this is what first came to my mind

Hope this helps
4 0
3 years ago
Please Help meeeeeeeeeee:
Akimi4 [234]

Answer:

D) save as

Explanation:

If you press save as it'll give you the option where to save to.

6 0
3 years ago
Read 2 more answers
Other questions:
  • Angela wrote some lines of code that she wants to test. She will need to use __________. IDLE open source a prompt a file path
    15·2 answers
  • What's does the Mutual Reward Theory state?
    10·1 answer
  • Define a Python function named file_listers with two parameters. The first parameter will be a string specifying the name of the
    7·1 answer
  • Your task is to improve a multi-threaded program that frequently writes small entries to a shared file by introducing a layer th
    7·1 answer
  • In the terms of OOP, in the microwave system, current time is a BLANK and change heat is a BLANK
    15·1 answer
  • You work part time at a computer repair store. You are in the process of building a new computer system. The customer wants a mo
    6·1 answer
  • Tulio is editing his video. He used the Trim Video tab. Tulio most likely changed the
    12·1 answer
  • The red dot says ‘you tried to read records from a table called “Netflix Content” but that table doesn’t exist in this’
    7·1 answer
  • Who is the father of computer​
    7·1 answer
  • An array called numbers contains 35 valid integer numbers. Determine and display how many of these values are greater than the a
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!