hello everyone,
so i need some help with a project i have for class. here is the project description.
First, you need to create a class called Player. This class should contain the following attributes:
1) Name
2) Health
3) Experience
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 set method and one get 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 display 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, a new file will be created (this is actually the easiest option as you only need to ask for a file name that will be used later when we save the file). 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. 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, health, experience) 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 choosing random numbers between 20-29 for health and experience and randomly choosing a name (we'll discuss how to do this in class, so make sure you come to class!). 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, health, experience), 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 to the current file name in the format specified below. 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 3 lines of the file are the information about the first player. As described above, players have a name, health, and experience. 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
Zadi Whattiz
23
27
Astro Zelmar
24
30
Juppi Vandokizmal
19
20
i am having a hard time with the following:: 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
any help?