I have a problem using ArrayLists. I am storing scores of games in a class called Game. Each "Game" class holds three scores and a date. The three scores are in an ArrayList.
Each game belongs to a class called Player. Each "Player" has multiple games.
Now when I want to display the scores of any given Player, I get the same result which is "9". 9 is the very first score that is entered into my program. When I take a look at the contents of the ArrayLists, I find that EVERY score ever entered is in one big ArrayList, instead of separated into ArrayLists of three scores each.
Here's an example of my code:
while (st.hasMoreTokens()) { strTemp = st.nextToken(); //gets a score scoreArray.add(strTemp); //stores a score into a ScoreArray } gameTmp = new Game(dateTmp, scoreArray); //Inserts a date, and the three scores from the ScoreArray //scoreArray.clear(); //I tried clearing the scoreArray, but that causes my program to crash playerTmp.addGame(gameTmp); //Adds the new game to a new player
But for some reason, ALL players use only one ArrayList of ALL the scores ever entered. Does anyone see the problem?