Results 1 to 1 of 1
I Have this program: It creates a federation that controls a series of tournaments, which are disputed and the points should go to the players according to their position in ...
- 11-29-2009 #1Just Joined!
- Join Date
- Aug 2005
- Posts
- 13
Problem with arrayList
I Have this program: It creates a federation that controls a series of tournaments, which are disputed and the points should go to the players according to their position in the tournament. I use an arraylist in which the players are positioned there based in the round of the tournament in which they lose. The loser of the first quarterfinal is putted in position 0, the one that loses in the second quarterfinal in position 1, and so on until the champion in the eight position.
Here is part of code of this program: (this is resume of the main class)
When I execute the first tournament, everything goes just fine, the players are putted in there as they should be and the points are distributed correctly.Code:import java.util.ArrayList; public class Federation { private int tournamentNumber; private ArrayList <Tournament> tournamentManager = new ArrayList<Tournament>(); public static void main(String[] args) { Federation federation = new Federation(); federation.controlActivities(); } public void controlActivities() { this.addTournament (this.createTournament("rolandGarros",200,140,90,50)); this.addTournament (this.createTournament("umag",30,20,15,10)); tournamentManager.get(0).playTournament(this.tournamentManager.get(0).getListPlayers()); this.updatePontuation(this.tournamentManager.get(0).getListPositions(), 0); tournamentManager.get(1).playTournament(this.tournamentManager.get(1).getListPlayers()); this.updatePontuation(this.tournamentManager.get(1).getListPositions(), 1); } private void updatePontuation(ArrayList <Player> positionList, int tournamentNumber) { int points; System.out.println (positionList.get(0).getPoints()); System.out.println (positionList.get(1).getPoints()); points = positionList.get(0).getPoints() + this.tournamentManager.get(tournamentNumber).getViceChampionPoints(); positionList.get(0).updatePoints(points); System.out.println (positionList.get(0).getName()); System.out.println (positionList.get(0).getPoints()); points = positionList.get(1).getPoints() + this.tournamentManager.get(tournamentNumber).getChampionPoints(); positionList.get(1).updatePoints(points); System.out.println (positionList.get(1).getName()); System.out.println (positionList.get(1).getPoints()); } public void addTournament(Tournament tournament) { tournamentManager.add (tournament); } }
But when I put the code to execute the second event,
it simply does not sum the points that a player got from the new tournament to its old ones. This is a call to the method that updates the points of a certain player in its constructor:Code:tournamentManager.get(1).playTournament(this.tournamentManager.get(1).getListPlayers()); this.updatePontuation(this.tournamentManager.get(1).getListPositions(), 1);
And this is the method:Code:positionList.get(1).updatePoints(points);
In fact, the points of the old one are erased. Here is the source code from another class that deals with the positioning of a player based on whether he wins the match or nott:Code:public void updatePoints(int points) { this.points = points; }
I don't know why this is happening. Anyone have and idea?Code:public void playTournament (ArrayList <Player> listaJogadores) { Match match1 = new Match(playersList.get(0), playersList.get(1)); match1.decideMatch (); match1.showWinner (); this.updatePositionList (0, match1); this.updatePositionList (1, match1); } public void updatePositionList (int decide, Match match) { if (decide == 0) this.positionList.add(match.getLoser()); if (decide == 1) this.positionList.add(match.getWinner()); }
Thanks for the help [


Reply With Quote