Basketball Avg

I trying to write a program that can take a multiple people's name and scoring avg then sort then highest to lowest, and also display the scoring avg for the entire team. But I don't know of anything that could store the avg for me and then calculate them at the end. I don't want to create fields at the beginning because I don't know how many people will play. Can anyone tell me what I should use so that I can figure out how to write this program?

~Kaeloc

[476 byte] By [Kaeloca] at [2007-11-27 2:11:26]
# 1
http://java.sun.com/j2se/1.5.0/docs/guide/collections/index.html
Lokoa at 2007-7-12 2:04:36 > top of Java-index,Java Essentials,New To Java...
# 2

Store them in an array or List. Then use Arrays.sort or Collections.sort

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html

http://java.sun.com/docs/books/tutorial/collections/

[url=http://www.onjava.com/lpt/a/3286]Making Java Objects Comparable[/url]

http://java.sun.com/docs/books/tutorial/collections/interfaces/order.html

http://www.javaworld.com/javaworld/jw-12-2002/jw-1227-sort.html

jverda at 2007-7-12 2:04:36 > top of Java-index,Java Essentials,New To Java...
# 3
I've heard of arrays, but I don't know how to use them...I will check the links.~Kaeloc
Kaeloca at 2007-7-12 2:04:36 > top of Java-index,Java Essentials,New To Java...
# 4
> I've heard of arrays, but I don't know how to use> them...> I will check the links.> > ~KaelocTutorial on using Array http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html
rym82a at 2007-7-12 2:04:36 > top of Java-index,Java Essentials,New To Java...
# 5
Make sure that your Players class (I made an assumption) has a compareTo(Object o) method, so that you can use .sort
shlumpha at 2007-7-12 2:04:36 > top of Java-index,Java Essentials,New To Java...
# 6

Here is some code that I have written so far.So when I am asking how many basketball players to process, I need to put the input into arrays? And do I put the array into the while statement or out of it?

~Kaeloc

public class basketball_avg {

public static void main(String[] args) {

basketball_avg basketball_avg = new basketball_avg();

System.out.print("How many basketball players do you want to process? "); //Asks how many players

System.out.flush();

int nplayers = cs1.Keyboard.readInt(); //Sets numbers of players

int player_number = 0;

while (player_number < nplayers)

{

player_number++;

System.out.println("Enter name for player #" + player_number + ": "); //Asks for player's name

//Here is where I need to put an array or something

System.out.println("Enter scoring avg for player #" + player_number + ": "); /*Sets scoring avg for player

I am going to round off the scoring avg to an int*/

}

System.out.println("*****************");

System.out.println("Team Scoring Report");

/*Here I need to sort the player's names and their scoring avg from highest scoring avg to lowest*/

System.out.println("*****************");

System.out.println("Highest Scoring Avg: ?"); //The highest avg goes where the question marks are

System.out.println("Lowest Scoring Avg: ?"); //The lowest avg goes where the question marks are

System.out.println("Average Scoring Avg: ?"); //The avg avg goes where the question marks are

}

}

Kaeloca at 2007-7-12 2:04:36 > top of Java-index,Java Essentials,New To Java...
# 7
out of the while loop to initialize array, otherwise will only be visible in the while loop, use the nplayers to initialize the size of the array,..hth
cafBeana at 2007-7-12 2:04:36 > top of Java-index,Java Essentials,New To Java...
# 8
Do I have to create 2 arrays for the player's names and another one for their scoring avg?~KaelocMessage was edited by: KaelocKaeloc
Kaeloca at 2007-7-12 2:04:36 > top of Java-index,Java Essentials,New To Java...
# 9
make it a 2-dimensional arrayor do it the same way as the class problem in your other post....Message was edited by: cafBean
cafBeana at 2007-7-12 2:04:36 > top of Java-index,Java Essentials,New To Java...