Jump to content

  • Log In with Google      Sign In   
  • Create Account

coltdaniel

Member Since 12 Jul 2009
Offline Last Active Mar 01 2014 02:11 AM

Posts I've Made

In Topic: Problem with arrayList

24 November 2009 - 11:02 AM

It ain't that. Note this code:

[sourcelang="java"]points = positionList.get(3).getPoints() + this.tournamentManager.get(tournamentNumber).getQuarterFinalistPoints();
positionList.get(3).updatePoints(points);



When the first tourament is executed, the fourth quarterfinalist gets its number of points, which should be zero, since the tournament just finished. Then these points are added to the number of points that a quarterfinalist of the tournamet should receive.
The sum of zero with X points, is then updated to the player's constructor

After the second tournament is executed, then the fourth quarterfinalist of the second event (whoever is), gets its X points from the previous tournament and sum it with the Y points that the quarterfinalist of the second event should receive. After that, the new amount of points is updated.

So my code doesn't depend on the updatePoints method to make the calculation, this is done in the updatePontuation method, the updatePoints one is just a "setter" method.

Any more ideas?

In Topic: Problem with array list in Java

12 July 2009 - 01:18 PM

I think I am understanding right now, "federation" doesn't call System.out.println, and since it is called from inside controlActivities, which, by it's turn, is called by "federationn", in the end is "federationn" that is calling system.out. Due to it, tournamentManager tries to get it's tournament objects, but there is nothing there, they belong to the tournamentManager of "federation", because it was "federation" that created those tournaments and added them to it's "own" tournamentManager list.

At least from a logical point of view this seems to make sense.

In Topic: Problem with array list in Java

12 July 2009 - 01:03 PM

Quote:
Original post by rip-off
Well, your problem stems from having two Federation instances. You are adding elements to the vector in one and printing them from another.

If you want to move code away from main() you need to create additional classes or functions that do what you want. But that is window dressing, the structure is pretty similar no matter where the code is.

Try this:
*** Source Snippet Removed ***
Note that the use of the "this" reference is unnecessary, but is used mainly for illustration.


It worked. I am somewhat confused about what really is going on. When "federationn" inside main calls controlActivities, all the objects created inside this method are going to belong to it?
So the "federation" created inside controlActivities is part of "federationn"?

I thought objects, created when an object call's a method that creates objects, didn`t belong to anybody, they just "existed".

Or not?
tournamentManager in my example is trying to get objects from where?
Are there two copies of tournamentManager, one belonging to "federation" and other to "federationn"?


In Topic: Problem with array list in Java

12 July 2009 - 11:49 AM

Quote:
Original post by rip-off
Why are you creating a new Federation instance in controlActivities? If you look at your code, you have 2 Federation instances, one created inside main() and another in controlActivities().


Because I don't want to control the program from inside the main method, so I created the first Federation just to it call controlActivities, and from there I do the Federation's management


In Topic: Problem with array list in Java

12 July 2009 - 11:13 AM

Quote:
Original post by rip-off
*** Source Snippet Removed ***
What class is this function in? You have a federation instance, which you add two Tournament instances to. But the last line references a "tournamentManager" directly. The instances are stored in the "tournamentManager" in "federation".


In Federation. The tournamentManager is the arrayList to store the tournament instances. Here is the full code source for the Federation class

import java.util.ArrayList;

public class Federation {

private ArrayList <Tournament> tournamentManager = new ArrayList<Tournament>();

public static void main(String[] args) {
Federation federationn = new Federation();
federationn.controlActivities();
}

public void controlActivities() {
Federation federation = new Federation();
federation.addsTournaments (federation.createsTournaments("rolandGarros",200,140,90,50));
federation.addsTournaments (federation.createsTournaments("umag",30,20,15,10));
//System.out.println(tournamentManager.get(0).retrievesChampion());
}

public Tournament createsTournaments(String name, int championPoints,int vice_championPoints, int semifinalistPoints, int quarterfinalistPoints) {
Tournament tournament = new Tournament(name, championPoints, vice_championPoints, semifinalistPoints, quarterfinalistPoints);
return tournament;
}

public void addsTournaments(Tournament tournament) {
tournamentManager.add (tournament);
}
}

PARTNERS