Results 1 to 5 of 5
- 12-11-2012, 11:03 PM #1
Member
- Join Date
- Dec 2012
- Posts
- 3
- Rep Power
- 0
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:
And my Main Class: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; } }
Thank you.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()); } } }Last edited by DaveDeviant; 12-12-2012 at 02:05 AM.
- 12-12-2012, 09:57 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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.
- 12-12-2012, 02:31 PM #3
Member
- Join Date
- Dec 2012
- Posts
- 3
- Rep Power
- 0
Re: List of 32 players with random attributes. How to select the ideal team?
- 12-12-2012, 02:46 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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.
Please do not ask for code as refusal often offends.
- 12-13-2012, 06:37 PM #5
Member
- Join Date
- Dec 2012
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Using a "Random" method to print out random index of Array List?
By RarkMowe in forum New To JavaReplies: 5Last Post: 10-24-2012, 09:17 PM -
Struts + Ajax select list
By franksniper in forum StrutsReplies: 0Last Post: 04-10-2012, 11:50 PM -
Populate select list with Java/Ajax
By Jeremy720 in forum JavaServer Pages (JSP) and JSTLReplies: 3Last Post: 04-20-2011, 03:14 PM -
Multi-Select List Box
By balleda in forum Advanced JavaReplies: 0Last Post: 03-03-2010, 07:10 AM -
Appending and item to a Select List
By Samurai Coder in forum New To JavaReplies: 1Last Post: 12-04-2009, 10:56 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
,
Bookmarks