Introduction
Please log into cs.bridgewater.edu and navigate to /csci102/hw/mar26. Write a program that satisfies the following requirements. When complete, please push your code to GitHub.
Program Specifications
Player.java
- The Player class should include fields for the player’s username (String) and current score(int).
- The class should set the username field in the constructor using an argument passed to the constructor.
- The class should have a setter for the current score field.
- The class should override toString() which should return a sensible string.
- The class should override equals() and consider two Player objects equal if they have the same username.
- The class should override hashCode().
- The class should implement the Comparable interface. Players are ordered according to their current score.
Driver.java
- Write a method named printPlayerArray() that takes an array of Players as an argument and prints the contents of the array using the Player class’ toString() method.
- Write a method named uniquePlayers() that takes an array of Players as an argument and returns a new array of Players where no two Player objects in the array are equal.
In the main() method, do the following
- Create 4 Player objects with the following data
- username: alice, current score: 50
- username: deathgrip; current score: 99
- username: puddles; current score: 21
- username: alice; current score: 67
- Add the 4 Player objects to an array of Players.
- Retrieve an array of unique Player objects by calling uniquePlayers().
- Sort the array of unique Players with the sort(Object[] a) method in the Arrays class.
- Print out the sorted array of unique Player objects.
- Print to the screen “Thank you professor for helping me be a better programmer”.
© 2021, Eric. All rights reserved.