Question: How to make this Java program, requirements are shown in pictures? It has two Classes:- Player class and Driver class called ComparePlayers. 1. Create a

How to make this Java program, requirements are shown in pictures?
It has two Classes:- Player class and Driver class called ComparePlayers.
 How to make this Java program, requirements are shown in pictures?
It has two Classes:- Player class and Driver class called ComparePlayers. 1.

1. Create a Java class called Player. The class should contain the following private instance variables i. ii. ili. String to store the name String to store the team name An int to store the player's jersey number 2. The Player class needs a constructor. It accepts three parameters, one for each instance variable. The constructor must enforce the following i. A player's name cannot be null or a String composed of whitespace. If the parameter passed to the constructor is null or a String composed of 2 of 5 COMP 1510 Bruce Link, Keith Tang, Patrick Guichon, Jeffrey Yim, Chris Thompson whitespace, the constructor must throw an lillegalArgumentException with a helpful, meaningful message. ii. A player's team cannot be null or a String composed of whitespace. If the parameter passed to the constructor is null or a String composed of whitespace, the constructor must throw an illegalArgumentException with a helpful, meaningful message A player's jersey number cannot be zero or negative. passed to the constructor is zero or negative, the constructor must throw an IllegalArgumentException with a helpful, meaningful message ili. If the parameter 3. Remember to document the rules for what is allowed and not allowed when creating a new Player in the constructor's Javadoc. know how to use your Player correctly Your Player class is immutable. Players should be easy to compare. This is so developers reading your class's API 4. 5. What does that mean about the instance variables? Modify your Player class so it implements the ComparablecPlayer> interface. You will have to implement the compareTo method. Sort Players by jersey number in ascending order. That is, when comparing two Players, the player with the lowest jersey number is first, and the player with the higher jersey number is second. 6. Okay let's redefine our first Object method. Implement a toString for the Player. The String returned by our toString method should contain the name, the team, and the jersey number. Label the data so the user can read it easily 7. Let's redefine our second Object method: implement an equals method for the Player The equals method should accept a single parameter of type Object called other, and return a boolean result indicating whether the parameter is "equal to this one (the Player executing the method). Here's the algorithm you should use inside the method: Check if the parameter equals null. If it does, then the Player executing the equals method is obviously not equal to it, so return false. a. b. Check if the Player executing the method ("this and the parameter are aliases. If so, then they are obviously two references to the same object, and we can return true. (Hint: remember we can compare two objects to see if they are aliases using) Check if the object passed as a parameter is an instance of the Player class. If it's not, then it's obviously not equal to "this Player executing the code and we can return false. We can check if the Object is a Player using the getClass method, which is also (surprisel) inherited from Object. Everything in Java has a getClass c- Player executing the method). Here's the algorithm you should use inside the method: Check if the parameter equals null. If it does, then the Player executing the equals method is obviously not equal to it, so return false Check if the Player executing the method ("this") and the parameter are aliases. If so, then they are obviously two references to the same object, and we can return true. (Hint: remember we can compare two objects to see if they are aliases using) check if the object passed as a parameter is an instance of the Player class. If it's not, then it's obviously not equal to "this" Player executing the code and we can return false. We can check if the Object is a Player using the getClass method, which is also (surprise!) inherited from Object. Everything in Java has a getClass method. We can use it like this: a. b. c, 1. if (IgetClassO.equalsCother.getclassO)) t 2. return false; d. Finally, if the parameter is not null, and it's not an alias, and it iS a Player, we can cast it as a player, and compare its name, team, and jersey number to "this Player's name, team, and jersey number. Return true if the names, teams, and jersey numbers are the same, otherwise return false. 8. Eclipse may complain after you create your equals method. It might say you need a hashCode method. We will learn about hashing and hash codes in COMP 2526. You can ignore this warning. The consequences of ignoring the warning means our Player class COMP 1510 Bruce Link, Keith Tang, Patrick Guichon, Jeffrey Yim, Chris Thompson will not work properly with some of the container classes that we have not seen in this course . Finally, let's create a driver class called ComparePlayers. ComparePlayers should: Contain a main method that drives the program. Create an array of Player large enough for 2 Players. Use a try-catch to try to create a Player with a null name or a name with only whitespace (just hardcode the parameters passed to the Player constructor), and catch the IllegalArgumentException and print its message Use a try-catch to try to create a Player with a null team or a team with only whitespace (just hardcode the parameters passed to the Player constructor), and catch the lllegalArgumentException and print its message Use a try-catch to try to create a Player with a negative jersey number (just hardcode the parameters passed to the Player constructor), and catch the IllegalArgumentException and print its message Ask the user for the name, team, and jersey number for a Player, instantiate a new Player, and store it in the array a. b. c. d. e. f. g. Ask the user for the name, team, and jersey number for a second Player, instantiate a new Player, and store it in the array. (Hint: reduce duplicated code by using a loop to do this and step f!) Report the result when the first Player is compared to the second Player using the compareTo method. Report whether the two players are equal. h

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!