The Artima Developer Community
Sponsored Link

Java Answers Forum
Search Function for Soccer tournement system. searching strings of arrays??

5 replies on 1 page. Most recent reply: Mar 14, 2005 11:30 PM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 5 replies on 1 page
chris

Posts: 6
Nickname: chriskq
Registered: Mar, 2005

Search Function for Soccer tournement system. searching strings of arrays?? Posted: Mar 9, 2005 5:00 PM
Reply to this message Reply
Advertisement
Hi all,
trying to make a soccer tournement management system primarily using Java with NetBeans.
Having trouble finding info on a SEARCH function. Would like to search either
- last name
- first name
- by suburb
- player jersey number. (search int, instead of string [just numbers])

basically there are 5 players in each team with 5 teams in total. All player data (Lname, Fname, ID, suburb) is going to be hardcoded into 2-dimensional Arrays

i am looking for some help to get started with the Java collection framework, using JDK 1.5. For example, suppose our array has a size of 5 (for the 5 teams).
Eg. suppose the array is called teams

for (int x = 0; x < 5; x + 1){
if (teams[x] == user search input)
JOptionPane.showMessageDialog ( show the player's
details)
}

but what do i do when i need to search and compare a Last Name (string)..
Any help would be great guysNgirls;
Cheers, Chris


chris

Posts: 6
Nickname: chriskq
Registered: Mar, 2005

Re: Search Function for Soccer tournement system. searching strings of arrays?? Posted: Mar 10, 2005 4:37 PM
Reply to this message Reply
player class Search {
public string Fname;
public string Lname;
int player_id;
public string suburb;
}
class Team {
Player [] all_players = new Player[5];

}
class Player{

}
class League{
Team [] all_teams = new Team [4];

}
class Schedual{

}
player [] allPlayers = new all_player[5];
allPlayers[0] = new all_players(); //object that represents one player
allPlayers[0].Fname = 'chris'
allPlayers[0].Lname = 'Ash'
allPlayers[0].id = '01'
allPlayers[0].suburb ='avalon'

allPlayers[1].Fname = 'ben'
allPlayers[1].Lname = 'dover'
allPlayers[1].id = '02'
allPlayers[1].suburb ='bondi'

allPlayers[2].Fname = 'Darren'
allPlayers[2].Lname = 'Shakka'
allPlayers[2].id = '03'
allPlayers[2].suburb ='westie vilee'

allPlayers[3].Fname = 'Axel'
allPlayers[3].Lname = 'Rose'
allPlayers[3].id = '03'
allPlayers[3].suburb ='CBD'

allPlayers[4].Fname = 'Mak'
allPlayers[4].Lname = 'Donald'
allPlayers[4].id = '04'
allPlayers[4].suburb ='shark island'

allPlayers[5].Fname = 'Gollie'
allPlayers[5].Lname = 'Macca'
allPlayers[5].id = '05'
allPlayers[5].suburb ='The Nulla'

player [] allPlayers = new all_player[5];
allPlayers[0] = new all_players();//object that represents one player
allPlayers[0].Fname = 'Never'
allPlayers[0].Lname = 'canHeadit'
allPlayers[0].id = '06'
allPlayers[0].suburb ='Morocco'

allPlayers[1].Fname = 'Grease'
allPlayers[1].Lname = 'Lighting'
allPlayers[1].id = '07'
allPlayers[1].suburb ='Italy'

allPlayers[2].Fname = 'Spearos'
allPlayers[2].Lname = 'Haddis'
allPlayers[2].id = '08'
allPlayers[2].suburb ='Rome'

allPlayers[3].Fname = 'Skate'
allPlayers[3].Lname = 'OrDie'
allPlayers[3].id = '09'
allPlayers[3].suburb ='Marys Cathedoral'

allPlayers[4].Fname = 'Caddie'
allPlayers[4].Lname = 'Shack'
allPlayers[4].id = '10'
allPlayers[4].suburb ='19th Hole

allPlayers[5].Fname = 'Tattered'
allPlayers[5].Lname = 'Rags'
allPlayers[5].id = '11'
allPlayers[5].suburb ='Locker 1a'

player [] allPlayers = new all_player[5];
allPlayers[6] = new all_players();//object that represents one player
allPlayers[6].Fname = 'Johnie'
allPlayers[6].Lname = 'boy'
allPlayers[6].id = '12'
allPlayers[6].suburb ='Down Under'

allPlayers[6].Fname = 'RollyourOwno'
allPlayers[6].Lname = 'Theodopalis'
allPlayers[1].id = '13'
allPlayers[1].suburb ='Liechardt'

allPlayers[2].Fname = 'Gwedo'
allPlayers[2].Lname = 'HearBall'
allPlayers[2].id = '14'
allPlayers[2].suburb ='Camperdown'

allPlayers[3].Fname = 'Lisa'
allPlayers[3].Lname = 'Simpson'
allPlayers[3].id = '15'
allPlayers[3].suburb ='Marys Cathedoral'

allPlayers[4].Fname = 'Caddie'
allPlayers[4].Lname = 'Shack'
allPlayers[4].id = '16'
allPlayers[4].suburb ='19th Hole

team_three[5].Fname = 'Tattered'
allPlayers[5].Lname = 'Rags'
allPlayers[5].id = '11'
allPlayers[5].suburb ='Locker 1a'

player [] allPlayers = new all_player[5];
allPlayers[6] = new all_players();//object that represents one player
allPlayers[6].Fname = 'Johnie'
allPlayers[6].Lname = 'boy'
allPlayers[6].id = '12'
allPlayers[6].suburb ='Down Under'

allPlayers[6].Fname = 'RollyourOwno'
allPlayers[6].Lname = 'Theodopalis'
allPlayers[1].id = '13'
allPlayers[1].suburb ='Liechardt'

allPlayers[2].Fname = 'Gwedo'
allPlayers[2].Lname = 'HearBall'
allPlayers[2].id = '14'
allPlayers[2].suburb ='Camperdown'

allPlayers[3].Fname = 'Lisa'
allPlayers[3].Lname = 'Simpson'
allPlayers[3].id = '15'
allPlayers[3].suburb ='Marys Cathedoral'

allPlayers[4].Fname = 'Caddie'
allPlayers[4].Lname = 'Shack'
allPlayers[4].id = '16'
allPlayers[4].suburb ='19th Hole

allPlayers[5].Fname = 'Tattered'
allPlayers[5].Lname = 'Rags'
allPlayers[5].id = '11'
allPlayers[5].suburb ='Locker 1a'

chris

Posts: 6
Nickname: chriskq
Registered: Mar, 2005

Re: Search Function for Soccer tournement system. searching strings of arrays?? Posted: Mar 10, 2005 4:38 PM
Reply to this message Reply
Sorry for posting a huge blob of text.
Really struggling on what to do next... want to hard code all player info into a all player class, but how do i segrigate the teams apart
there are 4 teams each with 5 players

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Search Function for Soccer tournement system. searching strings of arra Posted: Mar 14, 2005 8:51 AM
Reply to this message Reply
Add the team name as info to the player info.
If you don't, then you have to searchall teams for a player with this name.

I would not use String arrays at all.
this would be my approach to solve the problem.
Note that I wrote it in a standard text editor and did not compile it, so it might contain minor errors.
public class Team () {
    private String teamName;
    private boolean isUpdating;
    private boolean PlayerList myPlayers = new PlayerList();
 
    public Team (String teamName) {
        this.teamName = teamName;
    }
    public String getTeamName () {
    	return teamName;
    }
    public void addPlayer (Player p) {
        if (isUpdating)
            return;
        isUpdating = true;
        if (p != null) {
            if (!worksForMe(p)) {
            	p.workFor(this);
            	myPlayers.add(p);
            }
        }
        isUpdating = false;
    }
    public void removePlayer (Player p) {
        if (isUpdating)
            return;
        isUpdating = true;
        if (worksForMe) {
            myPlayers.remove (p);
            p.yourFired();
        }
        isUpdating = false;
    }
    private boolean worksForMe (Player p) {
    	if (p== null)
    	    return false;
    	return myPlayers.contains (p);
    }
}
 
public class Player () {
    String fName;
    String lName;
    String id;
    String suburb;
    Team workingFor = null;
 
    public Player (String fName, String lName, String id, String suburb) {
    	this.fname = fname;
    	this.lName = lName;
    	this.id = id;
    	this.suburb = suburb;
    }
    public String getFName () {
    	return fName;
    }
    public String getLName () {
    	return lName;
    }
    public String getID () {
    	return id;
    }
    public String getSuburb () {
    	return suburb;
    }
 
    public void workFor (Team newTeam) {
        if (isUpdating)
            return;
        isUpdating = true;
        if (workingFor != null)
            workingFor.removePlayer (this);
        workingFor = newTeam;
        if (newTeam != null)
        	newTeam.addPlayer (this);
        isUpdating = false;
    }
    public void yourFired () {
        if (isUpdating)
            return;
        isUpdating = true;
        if (workingFor != null)
            workingFor.removePlayer (this);
        isUpdating = false;
    }
    public Team getTeam () {
        return workingFor;
    }
}
 
 
 
public class PlayerList exteds Vector {
    /** Converts the returned Object into Player
     */
    public Player cGet(int index) {
        Object o = get(index);
        return (o == null) ? null : (Player)o;
    }
    public Player cGetLast(int index) {
        Object o = getLast();
        return (o == null) ? null : (Player)o;
    }
}
 
public class TeamList exteds Vector {
    /** Converts the returned Object into Player
     */
    public Team cGet(int index) {
        Object o = get(index);
        return (o == null) ? null : (Team)o;
    }
}
 
 
public class caller {
    public void main (String args[]) {
    	TeamList teams = new TeamList();
    	PlayerList allPlayers = new PlayerList();
    	for (int i = 0; i < 10; i++) {
            teams.add(new Team("Team " + i));
    	}
    	for (int i = 0; i < 100; i++) {
    		allPlayers.add(("fName" + i, "LName" + i, "pl" + i, "dada"));
    		allPlayers.cGetLast().workFor (teams.cGet (i % 10));
    	}
    	Player p = allPlayers.cGet ((int)Math.rnd() * 100);
    	System.out.println (p.getTeam().getTeamName());
    }
}

chris

Posts: 6
Nickname: chriskq
Registered: Mar, 2005

Re: Search Function for Soccer tournement system. searching strings of arra Posted: Mar 14, 2005 8:09 PM
Reply to this message Reply
thanks heaps for your advice neumi,
first time in couple of days since last checked and was really stoked. But i just have one more Q, you said u would not use String arrays at all.

what should i use then, bear in mind the info of all players has to be hard coded into something.

ps- i really like ur idea of adding team name to each player.

pss- if iv sed somthing really simple silly, pls forgive still a newbi

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Search Function for Soccer tournement system. searching strings of arra Posted: Mar 14, 2005 11:30 PM
Reply to this message Reply
You can see my alternative solution without String arrays in the example above.

I did NOT add the team name to the player, but a reference to the team itself. Everty team is an object, as is every player.

Using String arrays may be more efficient at times (for tables, etc.), but since you program using Java, you should create specialized classes for most objects.

A player is not just a collection of Strings, a player is a "human being", so create a class representing a player.

You have allways the possibility to hard code player info, but don't limit your possibilities using string arrays.

Flat View: This topic has 5 replies on 1 page
Topic: Anywhere I can find simple game codes? Previous Topic   Next Topic Topic: MergeSort Trouble

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use