generating soccer fixtures from a list of teams

From: zcraven (zaccraven_at_yahoo.co.uk)
Date: 10/29/04


Date: Fri, 29 Oct 2004 16:04:52 +0100

public void createFixtureList()
    {
        //setup 'cal' to get todays date
        Calendar cal = new GregorianCalendar();
        int y = cal.get(Calendar.YEAR);
        int m = cal.get(Calendar.MONTH); // 0=Jan, 1=Feb, ...
        m++; // 1=Jan, 2=Feb,
...
        int d = cal.get(Calendar.DAY_OF_MONTH);
        int hr = 15;
        int min = 00;

        int j = league.size();
        j--; // last club in league will have already had fixtures
generated by previous clubs
        for (int i=0; i<j; i++)
        {
            //get a CLUB(i) and create all possible fixtures for it
            Club c1 = (Club)league.get(i);
            for (int x=i+1; x<league.size(); x++)
            {
                // get an opponent club - CLUB(x) to create 2 fixtures
(home/away) with club(i)
                Club c2 = (Club)league.get(x);

                // HOME GAME - CLUB(i) vs CLUB(x)
                // set game date for one week after the previous club(i)
matchdate
                d = d+7;
                if (d > 23) // correct values 31->1
                {
                    m++;
                    d=(d-30);
                    if (m > 11) // correct values dec->jan
                    {
                        m = 1;
                        y++;
                    }
                }
                Calendar homedate = new GregorianCalendar(y, m, d, hr, min);
                Fixture f1 = new Fixture(c1.getGround(), homedate, c1, c2);
                fixtures.add(f1);

                // AWAY GAME CLUB(x) vs CLUB(i)
                // set away game for 6 months later
                int tempM = m;
                int tempY = y;
                m = (m+6);
                if (m > 12)
                {
                    m=(m-12);
                    y=y+1;
                }
                Calendar awaydate = new GregorianCalendar(y, m, d, hr, min);

                Fixture f2 = new Fixture(c2.getGround(), awaydate, c2, c1);
                fixtures.add(f2);

                // return m and y back to previous CLUB(i) homegame value
                m = tempM;
                y = tempY;
                homedate.clear();
                homedate.set(y,m,d,hr,min);
            }
        }
        printFixtureList();
    }

For some reason, the above code worked perfectly when I had 3 clubs in the
league. But since I added a 4th club, I always get a runtime error.

It generates all fixtures (8) for the first club (club(i)) perfectly. But
the problem occurs when it tries to increment i and get the next club to be
club(i). When it tries to get the club, it throws a 'null pointer
exception'. So the problem seems to be with the first FOR statement in the
above code.



Relevant Pages

  • Re: 7 club 3 count. how??!!
    ... All passes are doubles. ... Second person starts a little after the first club is past half way. ... I would recommend practicing lots of 6 club 3 count and throwing early ...
    (rec.juggling)
  • Re: Multiplexing with clubs
    ... I can do 5 clubs a bit but not with multiplexes. ... I use the circus grip but my ... I find that the one which has the top club pointing ... If I'm going to do a split multiplex, I tend to catch the first club, then ...
    (rec.juggling)
  • Re: catching 3rd club without hurting fingers - te
    ... >> Hi - I'm a new club juggler. ... And just hurt yourself, hurt yourself, hurt yourself? ... another finger) wrapped around the first club. ...
    (rec.juggling)
  • generating soccer fixtures from a list of teams
    ... For some reason, the above code worked perfectly when I had 3 clubs in the ... It generates all fixtures for the first club ) perfectly. ...
    (comp.lang.java.help)
  • Re: Whos here?
    ... Well that club can claim what they want, but Puget Sound Miata Club is ... you will find that the PSMC was the first club to register with them. ...
    (rec.autos.makers.mazda.miata)