Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objective and Overview: Exercise on User-defined classes. Homework maps to CLO-1 Exercise 1: (The Player class) Design a class named Player that contains a name

image text in transcribed

Objective and Overview: Exercise on User-defined classes. Homework maps to CLO-1 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 players in the file. (Hint: Use a while loop) 19. After reading all players, display the average of all players' average scores. 20. After reading all players, display the tallest player information using its toString() method

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

3rd Edition

0760049041, 978-0760049044

More Books

Students also viewed these Databases questions