Computers and Technology

Overriding the equals methodfile player. java contains a class that holds information about an athlete: name, team, and uniform number. file compareplayers. java contains a skeletal program that uses the player class to read in information about two baseball players and determine whether or not they are the same player.1. fill in the missing code in compareplayers so that it reads in two players and prints "same player" if they are the same, "different players" if they are different. use the equals method, which player inherits from the object class, to determine whether two players are the same. are the results what you expect? 2. the problem above is that as defined in the object class, equals does an address comparison. it says that two objects are the same if they live at the same memory location, that is, if the variables that hold references to them are aliases. the two player objects in this program are not aliases, so even if they contain exactly the same information they will be "not equal." to make equals compare the actual information in the object, you can override it with a definition specific to the class. it might make sense to say that two players are "equal" (the same player) if they are on the same team and have the same uniform number. use this strategy to define an equals method for the player class. your method should take a player object and return true if it is equal to the current object, false otherwise. test your compareplayers program using your modified player class. it should give the results you would expect.

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 06:00, Treezy11
In outlook how can cherie look at the details of an event that appears on the month view of her calendar? check all that apply. by switching to the detail view by switching to the week view by switching to the day view by right-clicking on the event by double-clicking on the event by highlighting the event
Answers: 2
image
Computers and Technology, 22.06.2019 21:30, mima851
Elements such as fonts colors visual structure graphics and the interface of a web page should complement each other to ensure blank
Answers: 3
image
Computers and Technology, 23.06.2019 03:10, nxusasmangaliso8780
Fill in the following program so that it will correctly calculate the price of the orange juice the user is buying based on the buy one get one sale.#include //main functionint main() { int cartons; float price, total; //prompt user for input information printf("what is the cost of one container of oj in dollars? \n"); scanf(" [ select ] ["%d", "%c", "%f", "%lf"] ", & price); printf("how many containers are you buying? \n"); scanf(" [ select ] ["%d", "%c", "%f", "%lf"] ", & cartons); if ( [ select ] ["cartons / 2", "cartons % 1", "cartons % 2", "cartons % price", "cartons / price", "cartons / total"] [ select ] ["=", "==", "! =", "< =", "> =", "< "] 0) total = [ select ] ["price * cartons", "cartons * price / 2 + price", "(cartons / 2) * price", "cartons / (2.0 * price)", "(cartons / 2.0) * price + price", "((cartons / 2) * price) + price"] ; else total = ((cartons / 2) * price) + price; printf("the total cost is $%.2f.\n", total); return 0; }
Answers: 2
image
Computers and Technology, 23.06.2019 13:30, powellmj9216
Spoons are designed to be used for: spring hammering. applying body filler. identifying high and low spots. sanding highly formed areas.
Answers: 3
Do you know the correct answer?
Overriding the equals methodfile player. java contains a class that holds information about an athle...

Questions in other subjects:

Konu
Mathematics, 28.04.2021 20:00
Konu
Mathematics, 28.04.2021 20:00
Konu
Mathematics, 28.04.2021 20:00
Konu
English, 28.04.2021 20:00