0

Java CompareTo() method for RPSPlayer

I'm having trouble understanding the concept of the compareTo() method and how to implement it in my RPSPlayer class. These files are based on Inheritance and some Polymorphism. For the pre-lab that I'm about to do I need to: "create a compareTo() method for the RPSPlayer class that will accept another RPSPlayer object as a parameter and will return an int according to these rules: if this RPSPlayer is less than the parameter RPSPlayer then the value returned is some integer less than zero if this RPSPlayer is greater than the parameter RPSPlayer then the value returned is some integer greater than zero if this RPSPlayer is equal to the parameter RPSPlayer then the value returned is zero" I need help on what to do for my compareTo() method in RPSPlayer. RPSPlayer > https://code.sololearn.com/cWnrHHMcq6Z6/#java HumanRPSPlayer > https://code.sololearn.com/cUyqBad4HEQJ/#java ComputerRPSPlayer > https://code.sololearn.com/chvz7yuNJaCQ/#java Driver > https://code.sololearn.com/cj5YL6fjaNCG/#java RPSPlayerContainer > https://code.sololearn.com/cOxr3nRHT0tu/#java

26th Feb 2019, 7:09 PM
Spartan Noah- 458
Spartan Noah- 458 - avatar
1 Answer
+ 2
compareTo ( ) function returns the ASCII difference between the first mismatched characters​ of the given strings. E.g: "Cat".compareTo("Cab") will return 18 as the first mismatched characters between the strings are 't'(118) and 'b' (98). So you will get a positive integer if the given string( which is being send a parameter to compareTo function) comes before in the dictionary order of the string it is being called upon and vice versa.
27th Feb 2019, 10:06 AM
Sinjini Das
Sinjini Das - avatar