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]

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
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
}
}
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