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 engineering firm you work for is submitting a proposal to create an amphitheater at a state park. Proposals must be submitte
NISA [10]

Answer: Accessibility

Explanation: Accessibility is the term that defines the availability of the data to the people and resources that has disability towards reaching it in accordance with technical communication. Certain regulations are made for the making the accessible documents.

The  divider tabs and index are put into every proposal binder so that every member is able to get knowledge about the content of the proposal .Thus, every person can access the three ring binder for gaining information about the creation of amphitheater.

8 0
3 years ago
A service that enables a customer to build and run their own applications but doesn't include extensive access to hardware and m
Musya8 [376]

There are a lot of computer apps. A service that enables a customer to build and run their own applications but doesn't include extensive access to hardware and middleware is PaaS.

<h3>What is PaaS?</h3>

This is known to be one that helps user to install and run their own application on any kind of vendor-supplied hardware and system software.

The Platform-as-a-Service, is said to be a cloud computing model that gives customers a full cloud platform such as hardware, software, and infrastructure that is used for creating, running, and handling applications.

Learn more about PaaS from

brainly.com/question/14364696

8 0
2 years ago
Why are networked systems beneficial?
Alexxx [7]
A many periphels can be used
5 0
4 years ago
Read 2 more answers
Can someone help me calculate this Multimedia math:
IRISSAK [1]

Answer:

I will try to help you answer this. it seems really confusing but I'll do my best to solve it and get it back to you. Hope I'm able to help!

5 0
3 years ago
Once a table is inserted into a publication, which two tabs become available?
rusak2 [61]

Answer:

insert i think sry if its wrong :(

Explanation:

7 0
3 years ago
Other questions:
  • Your desktop computer monitor is not displaying a picture. What would you do to troubleshoot the problem?
    9·2 answers
  • Being technologically literate requires being able to ______.
    11·2 answers
  • Which of the following is similar to defense in depth and supports multiple layers of security?a. Defense in depthb. Diversity o
    7·1 answer
  • Let's say that you're the sole IT person in your company, and your boss wants a way to block certain websites from employees. Wh
    6·2 answers
  • Selective colleges choose to have in-person meetings to learn more about the applicants. These meetings are called:
    8·2 answers
  • 3 uses of Microsoft word in hospital
    10·1 answer
  • Write a function, AvgList, that takes a single argument, a list, and returns the average (mean) of the numbers in the list. You
    10·1 answer
  • How did people figure qwerty keyboard set up, instead of the abcdef setup?
    13·1 answer
  • WILL GIVE A BRAINLIEST!!! PLS HELP!!!
    5·1 answer
  • Draw and implement of an organization which have 125 employees. use the following features 1.email services 2.lan communication
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!