Issue
I'm building some kind of game for programming class and I need to have a history of the people who played, you can play multiple times when you run the game, so I'm not trying to store it permanently just when the game is executing.
I was thinking maybe some kind of array or something that can store all the string variables (names), but I don't how to do this indefinitely until the game stops.
Also, I am not allowed use java data structures (ArrayList, LinkedList, etc.) .
Alternatively, if this is not possible or very complicated, maybe some way to store the names of only the last 10 people that play would work.
Any help is appreciated.
Solution
If data structures are not allowed, you could actually just make do of a comma-delimited String because an array in order to initialize you need to specify its size already (but this is something you definitely cannot know yet). Have a static instance of the String, then append to it a delimiter (comma) and the the player name.
private static String commaDelimitedStr = "";
public void addPlayerName (String playerName) {
commaDelimitedStr = commaDelimitedStr.concat(",").concat(playerName);
}
Then at the end you can split the String to get an array version of it.
String[] names = commaDelimitedStr.split(",");
Answered By - lorraine
Answer Checked By - David Goodson (JavaFixing Volunteer)