For this you will be writing a program that provides information about tennis players. I have provided
Question:
For this you will be writing a program that provides information about tennis players. I have provided a file called womenSinglesDraw.txt that contains a list of players who qualified for the women's singles event in the 2020 Australian Open. Each line contains the name, age, rank, and home country for each player. Note that both the name and the country may include spaces. For example, the first line of the file looks like this:
Ashleigh Barty,23,1,Australia
The information for each player should be stored in a Player object.
The Player class should contain the following:
- Private instance variables for the name, age, rank and home country of the player.
- A constructor that takes four arguments corresponding to the name, age, rank, and home country of the player and initializes the corresponding private instance variables.
- Getters and setters for each of the private instance variables.
- A toString function that returns a string containing the player information in the following format:
- Name: Ashleigh Barty Age: 23 Rank: 1 Country: Australia
You will also need to include a NoSuchPlayerException class that is derived from the Exception class for use in your program.
Your main program should contain the following static methods:
- loadPlayers takes a string filename and an array of Player objects as arguments and stores a new Player object in the array for each line of the file. It should handle any IO exceptions on its own.
- displayMenu takes no arguments and displays the following menu:
- Choose one of the following options: 1. Find a player by name 2. Find all players from a country 3. Find the youngest player 4. Find the oldest player 5. Exit
- findPlayerByName takes an array of Player objects and a string name and returns the first player with that name. If no player with that name can be found, it throws a NoSuchPlayerException.
- findPlayersByCountry takes an array of Player objects and a string country and returns an array containing only the players from that country. If no players from that country can be found, it throws a NoSuchPlayerException.
- findYoungestPlayer takes an array of Player objects and returns the youngest player. If there are no players in the array (all of the entries are null), it throws a NoSuchPlayerException.
- findOldestPlayer takes an array of Player objects and returns the oldest player. If there are no players in the array (all of the entries are null), it throws a NoSuchPlayerException.
- main does the following:
- Uses loadPlayers to load the player information from the womenSinglesDraw.txt file into an array of Player objects.
- Uses displayMenu to display the menu, and prompts the user to enter a choice.
- If the user enters 1, prompts them for a name and uses findPlayerByName to find the corresponding player and displays their information.
- If the user enters 2, prompts them for a country and uses findPlayersByCountry to find the corresponding players and displays their names.
- If the user enters 3, uses findYoungestPlayer to find and display the youngest player's information.
- If the user enters 4, uses findOldestPlayer to find and display the youngest player's information.
- If the user enters 5, exits the program.
- If the user enters any other number, displays an error message.
- Once the user's choice has been processed, go back to step 2 unless the user chose to exit the program.
- All calls to functions that throw a NoSuchPlayerException should be made in a try block whose corresponding catch block displays an appropriate error message.
Example Input and Output
Loading players from file Choose one of the following options: 1. Find a player by name 2. Find all players from a country 3. Find the youngest player 4. Find the oldest player 5. Exit Enter choice: 6 Invalid Choice Choose one of the following options: 1. Find a player by name 2. Find all players from a country 3. Find the youngest player 4. Find the oldest player 5. Exit Enter choice: 1 Please enter the player's name: Steffi Graf There is no player named Steffi Graf Choose one of the following options: 1. Find a player by name 2. Find all players from a country 3. Find the youngest player 4. Find the oldest player 5. Exit Enter choice: 1 Please enter the player's name: Simona Halep Name: Simona Halep Age: 28 Rank: 3 Country: Romania Choose one of the following options: 1. Find a player by name 2. Find all players from a country 3. Find the youngest player 4. Find the oldest player 5. Exit Enter choice: 2 Please enter the country: Ireland There are no players from Ireland Choose one of the following options: 1. Find a player by name 2. Find all players from a country 3. Find the youngest player 4. Find the oldest player 5. Exit Enter choice: 2 Please enter the country: Czech Republic Barbora Krejcikova Katerina Siniakova Petra Kvitova Marie Bouzkova Barbora Strycova Kristyna Pliskova Karolina Muchova Marketa Vondrousova Karolina Pliskova Choose one of the following options: 1. Find a player by name 2. Find all players from a country 3. Find the youngest player 4. Find the oldest player 5. Exit Enter choice: 3 Name: Cori Gauff Age: 15 Rank: 67 Country: United States Choose one of the following options: 1. Find a player by name 2. Find all players from a country 3. Find the youngest player 4. Find the oldest player 5. Exit Enter choice: 4 Name: Venus Williams Age: 39 Rank: 55 Country: United States Choose one of the following options: 1. Find a player by name 2. Find all players from a country 3. Find the youngest player 4. Find the oldest player 5. Exit Enter choice: 5 Program Exiting.
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill