Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By Tolls

Thread: List of 32 players with random attributes. How to select the ideal team?

  1. #1
    DaveDeviant is offline Member
    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Default List of 32 players with random attributes. How to select the ideal team?

    Hi. I have a list of 32 players with some random attributes. Now I need to select the ideal 11 by calculating the attributes average of every player.
    PS: I'm new to Java :D

    Here is my code:
    Java Code:
    package it.Calciatore;
    
    public class Calciatore {
    	private String name;
    	private int strength;
    	private int shooting;
    	private int header;
    	private int tackling;
    	
    	public Calciatore(String name, int strength, int shooting, int header, int tackling) {
    		this.name = name;
    		this.strength = strength;
    		this.shooting = shooting;
    		this.header = header;
    		this.tackling = tackling;
    	}
    	public Calciatore() {
    
    	}	
    	public String getName() {
    		return name;
    	}
    	public void setNome(String name) {
    		this.name = name;
    	}
    	public int getStrength() {
    		return strength;
    	}
    	public void setStrength(int strength) {
    		this.strength = strength;
    	}
    	public int getShooting() {
    		return shooting;
    	}
    	public void setShooting(int shooting) {
    		this.shooting = shooting;
    	}
    	public int getHeader() {
    		return header;
    	}
    	public void setHeader(int header) {
    		this.header = header;
    	}
    	public int getTackling() {
    		return tackling;
    	}
    	public void setTackling(int tackling) {
    		this.tackling = tackling;
    	}
    }
    And my Main Class:
    Java Code:
    package it.CalciatoreRun;
    import it.Calciatore.Calciatore;
    import java.util.*;
    
    public class RunCalciatore {
    	public static void main(String[] args) {
    		List <Calciatore> calciatoreList = new ArrayList <Calciatore>();		
    		Random rndNumbers = new Random();
    		for (int n=1; n<=32; n++) {
    			Calciatore c=new Calciatore("Name"+ n, rndNumbers.nextInt(100), rndNumbers.nextInt(100),
     rndNumbers.nextInt(100), rndNumbers.nextInt(100));
    			calciatoreList.add(c);
    		}
    		for (Calciatore c:calciatoreList) {
    			System.out.println(c.getName()+" Strength:" + c.getStrength()+" Shooting:"+c.getShooting()+" 
    Header:"+c.getHeader()+" Tackling:"+ c.getTackling());
    		}
    		
    	}
    }
    Thank you.
    Last edited by DaveDeviant; 12-12-2012 at 02:05 AM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: List of 32 players with random attributes. How to select the ideal team?

    Give each Calciatore a "rating" that is the average of their attributes.
    You can then either make Calciatore implement Comparable, or you can create a Comparator, and use Collections.sort on your array, then printing out the first 11.
    Please do not ask for code as refusal often offends.

  3. #3
    DaveDeviant is offline Member
    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Default Re: List of 32 players with random attributes. How to select the ideal team?

    Quote Originally Posted by Tolls View Post
    Give each Calciatore a "rating" that is the average of their attributes.
    You can then either make Calciatore implement Comparable, or you can create a Comparator, and use Collections.sort on your array, then printing out the first 11.
    Hi Tolls, thanks for reply. Someone told me I can use the 'calciatoreList' in order to do that, something with double and getlist and use them in my
    Java Code:
    public class Calciatore
    .
    I didn't understood very well how to do that.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: List of 32 players with random attributes. How to select the ideal team?

    I've just told you how to do it, complete with links to all the relevant classes.
    DarrylBurke likes this.
    Please do not ask for code as refusal often offends.

  5. #5
    DaveDeviant is offline Member
    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Default Re: List of 32 players with random attributes. How to select the ideal team?

    Quote Originally Posted by Tolls View Post
    I've just told you how to do it, complete with links to all the relevant classes.
    I've done it.
    Thank you ,
    Dave

Similar Threads

  1. Replies: 5
    Last Post: 10-24-2012, 09:17 PM
  2. Struts + Ajax select list
    By franksniper in forum Struts
    Replies: 0
    Last Post: 04-10-2012, 11:50 PM
  3. Populate select list with Java/Ajax
    By Jeremy720 in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 04-20-2011, 03:14 PM
  4. Multi-Select List Box
    By balleda in forum Advanced Java
    Replies: 0
    Last Post: 03-03-2010, 07:10 AM
  5. Appending and item to a Select List
    By Samurai Coder in forum New To Java
    Replies: 1
    Last Post: 12-04-2009, 10:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •