Results 1 to 1 of 1
- 12-02-2009, 01:14 AM #1
Member
- Join Date
- Dec 2009
- Posts
- 12
- Rep Power
- 0
Problem with keeping values into an 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.Java 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:Java Code:tournamentManager.get(1).playTournament(this.tournamentManager.get(1).getListPlayers()); this.updatePontuation(this.tournamentManager.get(1).getListPositions(), 1);
And this is the method:Java 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:Java Code:public void updatePoints(int points) { this.points = points; }
I don't know why this is happening. Anyone have and idea?Java 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
Similar Threads
-
adding values from file to multi-dimensional ArrayList
By sebo in forum New To JavaReplies: 7Last Post: 09-26-2011, 11:29 PM -
Java Keeping Text in One Place
By xpngamer in forum New To JavaReplies: 1Last Post: 04-09-2009, 06:27 AM -
trying to set() values of in list of arraylist
By alvations in forum New To JavaReplies: 15Last Post: 10-13-2008, 09:35 PM -
Need some help bad, at wits end validating this form and keeping script.
By bastardpete in forum New To JavaReplies: 1Last Post: 08-27-2008, 04:27 AM -
POI for delete excel record with keeping the existing macros
By Jay in forum Advanced JavaReplies: 0Last Post: 07-31-2008, 10:44 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks