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

Topics I've Started

Changing color background

03 February 2013 - 10:39 PM

There is a way to do this? The white background is very irritating to the eyes when I am in a fairly dark environment (which is all the cases of myself acessing it). There is a way to use the old blue background?


Problem with arrayList

23 November 2009 - 03:40 PM

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 most of the main class)
[sourcelang="java"]
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());
    	System.out.println (positionList.get(2).getPoints());
    	System.out.println (positionList.get(3).getPoints());
    	System.out.println (positionList.get(4).getPoints());
    	System.out.println (positionList.get(5).getPoints());
    	System.out.println (positionList.get(6).getPoints());
    	System.out.println (positionList.get(7).getPoints());
    	System.out.println (tournamentManager.get(0).getSemiFinalistPoints());
    	System.out.println (tournamentManager.get(1).getSemiFinalistPoints());
		points = positionList.get(0).getPoints() + this.tournamentManager.get(tournamentNumber).getQuarterFinalistPoints();
		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).getQuarterFinalistPoints();
		positionList.get(1).updatePoints(points);
		System.out.println (positionList.get(1).getName());
		System.out.println (positionList.get(1).getPoints());
		points = positionList.get(2).getPoints() + this.tournamentManager.get(tournamentNumber).getQuarterFinalistPoints();
		positionList.get(2).updatePoints(points);
		System.out.println (positionList.get(2).getName());
		System.out.println (positionList.get(2).getPoints());
		points = positionList.get(3).getPoints() + this.tournamentManager.get(tournamentNumber).getQuarterFinalistPoints();
		positionList.get(3).updatePoints(points);
		System.out.println (positionList.get(3).getName());
		System.out.println (positionList.get(3).getPoints());
		points = positionList.get(4).getPoints() + this.tournamentManager.get(tournamentNumber).getSemiFinalistPoints();
		positionList.get(4).updatePoints(points);
		System.out.println (positionList.get(4).getName());
		System.out.println (positionList.get(4).getPoints());
		points = positionList.get(5).getPoints() + this.tournamentManager.get(tournamentNumber).getSemiFinalistPoints();
		positionList.get(5).updatePoints(points);
		System.out.println (positionList.get(5).getName());
		System.out.println (positionList.get(5).getPoints());
		points = positionList.get(6).getPoints() + this.tournamentManager.get(tournamentNumber).getViceChampionPoints();
		positionList.get(6).updatePoints(points);
		System.out.println (positionList.get(6).getName());
		System.out.println (positionList.get(6).getPoints());
		points = positionList.get(7).getPoints() + this.tournamentManager.get(tournamentNumber).getChampionPoints();
		positionList.get(7).updatePoints(points);
		System.out.println (positionList.get(7).getName());
		System.out.println (positionList.get(7).getPoints());
	}

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

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. But when I put the code to execute the second event,
[sourcelang="java"]
tournamentManager.get(1).playTournament(this.tournamentManager.get(1).getListPlayers());
this.updatePontuation(this.tournamentManager.get(1).getListPositions(), 1); 

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:
[sourcelang="java"]
positionList.get(2).updatePoints(points);

And this is the method:
[sourcelang="java"]
public void updatePoints(int points) {
		this.points = 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:
[sourcelang="java"]
                   private ArrayList <Player> positionList = new ArrayList<Player>(); 
                   Match match7 = new Match(match5.getWinner(), match6.getWinner());
		   match7.decideMatch ();
		   match7.showWinner  ();
		   this.updatePositionList (0, match7);
		   this.updatePositionList (1, match7);
	}
	
	public void updatePositionList (int decide, Match match) {
		if (decide == 0)
		    this.positionList.add(match.getLoser());
		if (decide == 1)
			this.positionList.add(match.getWinner());
	}

I don't know why this is happening. Anyone have and idea? Thanks for the help

Problem with array list in Java

12 July 2009 - 08:32 AM

I am trying to add a bunch of objects to an arrayList and them to print the values of one of the fields of these objects through a System.out.println. Inside System.out, the arrayList uses get to obtain its object number 0, and them send the object to use a getter method of its class to obtain the value of one of its fields, the value that should be printed But then I receive: Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.RangeCheck(Unknown Source) at java.util.ArrayList.get(Unknown Source) What can be? Although not related to this, there is a problem in adding lots of objects with the same name to an arrayList? I guess not, since every time I invoke the method responsible for adding the objects to the arrayList, its gonna add them to sequential positions, but I wanna be sure

How I can post code?

12 July 2009 - 07:58 AM

Normally I use
dggfdghghdd
to enter code in another foruns, but here it doesnt work and I dont have any visible option to manipulate text when I post a message. What can I do?

PARTNERS