Answered step by step
Verified Expert Solution
Question
1 Approved Answer
java form Exercise 1: (The Player class) Design a class named Player that contains a name (String), a height (double), and three scores (array of
java form
Exercise 1: (The Player class) Design a class named Player that contains a name (String), a height (double), and three scores (array of int). 1. Create the class Player with all its attributes. Make all attributes private. 2. Create a default constructor for the class Player. 3. Create an Initialization constructor for the class Player to initialize all attributes. 4. Create a copy constructor for the class Player 5. Create public accessors and mutators for all attributes of the class Player. 6. Create the toString() method in the class Player to return a string that represents all attributes inside the class. 7. Add a public method called equals to return true if two players are equal, and false otherwise. Two players are equal if they have the same name, height, and three scores. 8. Add a public compareTo() method to the class player to compare two players to each other. The players will compare by their names only. 9. Add a public method getAverageScore() in the class Player to return the average score for a player. 10. Create another class with a main method, call it TestPlayer. 11. In the main method, create a player p1 using the default constructor with name = "Salama", height =1.7, scores are [102,105, and 110]. (Hint: Use the setters and getter after you create the player with the default constructor] 12. Display the player p1 using its tostring() method 13. Display the average score for the player p1 using the getAveragescore() method 14. Create another player p2 using the initialization constructor with name = "Mariam", height = 1.65, scores [79,85,92] 15. Display the player p2 using its tostring() method 16. Display the total grade for the player p2 using the getAverageScore() method 17. Create a player p3 which is a copy of p2 (Hint: Use the copy constructor) and display it using the tostring() method 18. Open a file, called "players.txt" and read all lines in the file one by one. When reading a player info, create a Player object, and display it using its tostring(). Assume that you do not know the total number of plavers in the file. (Hint: Use a while loop) 19. After reading all players, display the average of all plavers' average scores. 20. After reading all players, display the tallest player information using its tostring() method. Sample input file Amal1.6211010875 Sarah1.708518572 Noura1.5993102103 Alia1.659410992 Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started