In my Java class, we have to randomly create basketball teams and random scores, then average the scores for each team, and average the scores for each game. I am not sure how to average the score for each game, meaning adding scores vertically in a vector versus adding scores horizontally. I have tried using a totaling mechanism in any of the for loops, but of course they all added across, not vertically. What I would like to do is just total the scores vertically, and use seperate code to get the average, much easier I think. The code so far is below:
import java.text.DecimalFormat;
import java.util.*;
public class Assignment7{
public Vector boardScores = new Vector();
public Vector avgVector = new Vector();
public int numOfTeams = 0;
public int numOfGames = 0;
public int youScored;
public int MintScore;
public int RepeatNumbers;
public static void main(String args[]){
Assignment7 myStatsBoard = new Assignment7();
myStatsBoard.killMe();
}
public Assignment7(){
}
public void killMe(){
readNumberOfTeams();
readNumberOfGames();
getTheGameScores();
calculateTheAverage();
displayStatsBoard();
}
public void readNumberOfTeams(){
int teamNumbers = 0;
Random myRandomTeam = new Random();
boolean stopTheRunaround = false;
while(!stopTheRunaround){
teamNumbers = myRandomTeam.nextInt(10);
if (teamNumbers > 5){
stopTheRunaround = true;
}
}
setNumberOfTeams(teamNumbers);
}
public void readNumberOfGames(){
Random myRandomTeam = new Random();
int gameNumber = myRandomTeam.nextInt(12);
while(gameNumber <= 6){
gameNumber = myRandomTeam.nextInt(12);
}
setNumberOfGames(gameNumber);
}
public void getTheGameScores(){
RepeatNumbers = 0; //I initialize RepeatNumbers to
for (int i = 0; i < getNumberOfTeams(); i ++){ //use to capture numbers from
Vector teamVector = new Vector(); //vector.
RepeatNumbers = (Integer) teamVector.get(i); //<-- Test if this will get me
for (int j = 0; j < getNumberOfGames(); j++){//the numbers vertically, but
teamVector.add("" + getMyNumberNow()); //creates error when
} //trying to build program.
boardScores.add(teamVector);
}
}
public int getMyNumberNow(){
Random myRandomTeam = new Random();
int nextStupidRandomNumber = 0;
while(nextStupidRandomNumber < 1 || nextStupidRandomNumber > 150){
nextStupidRandomNumber = myRandomTeam.nextInt(1500);
}
return nextStupidRandomNumber;
}
public void calculateTheAverage(){
int TotalScore = 0;
for (int i = 0; i < getNumberOfTeams(); i++){
Vector teamVector = (Vector) boardScores.get(i);
for (int j = 0; j < getNumberOfGames(); j++){
String whatScore = (String) teamVector.get(j);
MintScore = Integer.parseInt(whatScore);
youScored = youScored + MintScore;
}
double averageScore = (double) youScored / getNumberOfGames();
avgVector.add("" + averageScore);
}
}
public void displayStatsBoard(){
DecimalFormat format = new DecimalFormat("###,###,##0.00");
System.out.println("\n\nThis is Steven Peterson's Scorecard\n\n");
System.out.println("Total Teams: " + getNumberOfTeams());
System.out.println("Total Games: " + getNumberOfGames());
System.out.println("\n\nTeam Scoreboard\n");
System.out.print("\t\t");
for (int k = 0; k < getNumberOfGames(); k++){
System.out.print("Game" + (k + 1) + "\t");
}
System.out.print("Average");
for (int i = 0; i < getNumberOfTeams(); i ++){
System.out.print("\nTeam " + (i + 1) + "\t\t");
Vector teamVector = (Vector) boardScores.get(i);
for (int j = 0; j < getNumberOfGames(); j++){
String whatScore = (String) teamVector.get(j);
System.out.print(whatScore + "\t");
}
String avg = (String) avgVector.get(i);
double dblAvg = Double.parseDouble(avg);
System.out.print(format.format(dblAvg));
}
System.out.println(""); System.out.println("");
}
public int getNumberOfTeams(){
return numOfTeams;
}
public int getNumberOfGames(){
return numOfGames;
}
public void setNumberOfGames(int _numberOfGames){
numOfGames = _numberOfGames;
}
public void setNumberOfTeams(int _numberOfTeams){
numOfTeams = _numberOfTeams;
}
}