Objectives:

To review classes, creation and manipulation of objects, and reading from and writing to text files.

Description:

First, you need to create a class called Player. This class should contain the following attributes:

1) name (a string)
2) age (an integer)

This information should only be accessible through methods of the Player class.

First we have constructors. You must write one default constructor for the Player class.

Second are the access methods. These allow you to get and set members of the class. You must write one setter method and one getter method for each of the attributes.

Third we have the functionality methods. These are methods that allow our class to perform additional actions. For example, you should write a method to print the information about a player to the screen.

Your program should begin with the following menu:

1) New File
2) Open File
3) Quit

If the user selects option 1, just have the program proceed to the second menu (see below). If the user selects option 2, you should ask for a file name to open and read the contents of that file into an array of type Player (assume there will never be more than 20 players in any file). The file format will be explained below. The program should then proceed to the next menu. Option 3 should allow the program to end.

If the user did not select option 3 from the first menu, then bring up the second menu:

1) Print all Players
2) Create a new Player
3) Randomly generate a new Player
4) Modify a Player
5) Save Player list
6) Close File

If the user selects option 1 from this menu, then your program should display all of the Players' information. If the user selects option 2, then you should ask for all the data about a Player (name and age) and put this new player into the array at the next available spot. If the user selects option 3, then you should have your program randomly create a Player by randomly choosing a name and an age. This Player should be placed in the next available spot in the array. If the user selects option 4, ask for the name of the Player they'd like to modify. If the Player is in the array, then ask what attribute they'd like to modify (name or age), get the new value, and then set the Player's attribute to this new value. If the player does not exist, give an error message. Option 5 should save the player data in the format specified below to a file name specified by the user. Option 6 should return the program to the first menu.

NOTE: When adding new Players to the array, never allow the total number to go over 20. Give an error message if the user tries to do this.

THE DATA FILE:

The data file must take the format described here. You can assume there will never be more than 20 Players in a file. Data is organized such that there is only one piece of information per line. The first line of the file tells us how many Players there are. The next 2 lines of the file are the information about the first player. As described above, players have a name and an age. Following the data about the first player is the data about the second, and so on until all players have been specified. Here is a sample data file:

3
Martian
14
Astro
873
Alien
52

Requirements:

As with all programs you create for this course, there should be some error checking. For example, the program should not accept illegal values. If an illegal value is entered, a message should be given and the user should be prompted for the value again.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.